실행코드
libname certdata '/folders/mypath/cert/heart.xlsx';
data work.heart;
set certdata.heart (drop= AgeAtDeath DeathCause);
where Status='Alive';
if AgeCHDdiag =. then delete;
length Smoking_Status $17;
if 0 <= Smoking <6 then Smoking_Status = 'None (0-5)';
else if 6 <= Smoking <16 then Smoking_Status = 'Moderate (6-15)';
else if 16 <= Smoking <26 then Smoking_Status = 'Heavy (16-25)';
else if Smoking > 25 then Smoking_Status = 'Very Heavy (>25)';
else Smoking_Status = 'Error';
run;
proc freq data = work.heart;
tables AgeCHDdiag * Smoking_Status / norow nocol nopercent;
run;
해설
libname certdata XLSX '/folders/mypath/cert/heart.xlsx'; # 오류떠서 xlsx 빼고 실행하니 작동함
NOTE: 데이터 가져오기가 취소되었습니다.
125 libname certdata XLSX '/folders/mypath/cert/heart.xlsx';
ERROR: XLSX 엔진을 찾을 수 없습니다.
ERROR: LIBNAME 문장에 오류가 있습니다.
data work.heart;
set certdata.heart (drop= AgeAtDeath DeathCause);
where Status='Alive';
Q. If the AgeCHDdiag variable has a missing value(.), then do not include the value in Work.Heart
if AgeCHDdiag =. then delete; # Missing value 에 대한 처리
Q. Create a new variable Smoking_Status, set its length to 17 characters
length Smoking_Status $17; # 문자 길이 지정
if 0 <= Smoking <6 then Smoking_Status = 'None (0-5)';
# if 문 등호조건 한 번에 작성 가능 (if 0 <= Smoking and Smoking < 6 으로 따로 쓰지 않기)
else if 6 <= Smoking <16 then Smoking_Status = 'Moderate (6-15)'; # 두 번째 조건부터 else if
else if 16 <= Smoking <26 then Smoking_Status = 'Heavy (16-25)';
else if Smoking > 25 then Smoking_Status = 'Very Heavy (>25)';
else Smoking_Status = 'Error';
run;
proc freq data = work.heart;
Q. supress column percentage, row percentage and cell percentage
tables AgeCHDdiag * Smoking_Status / norow nocol nopercent ;
run;
정답
libname certdata XLSX '/folders/mypath/cert/heart.xlsx';
data work.heart;
set certdata.heart (drop= AgeAtDeath DeathCause);
where Status='Alive';
if AgeCHDdiag =. then delete;
length Smoking_Status $17;
if 0 <= Smoking <6 then Smoking_Status = 'None (0-5)';
else if 6 <= Smoking <16 then Smoking_Status = 'Moderate (6-15)';
else if 16 <= Smoking <26 then Smoking_Status = 'Heavy (16-25)';
else if Smoking > 25 then Smoking_Status = 'Very Heavy (>25)';
else Smoking_Status = 'Error';
run;
proc freq data = work.heart;
tables AgeCHDdiag * Smoking_Status / norow nocol nopercent;
run;

'SAS > Scenario' 카테고리의 다른 글
| Scenario 1 (0) | 2022.12.25 |
|---|---|
| Scenarie 10 (0) | 2022.11.06 |
| Scenario 9 (1) | 2022.11.06 |
| Scenario 8 (0) | 2022.11.06 |
| scenario 7 (0) | 2022.11.06 |