38. The following SAS program is submitted:
%macro execute;
<insert statement here>
proc print data = sasuser.houses;
run;
%end;
%mend;
Which of the following completes the above program so that it executes on Tuesday?
A. %if &sysday = Tuesday %then %do;
B. %if &sysday = ‘ Tuesday' %then %do;
C. %if “&sysday” = Tuesday %then %do;
D. %if ‘&sysday’ = ‘ Tuesday' %then %do;
[정답]A
[풀이]
매크로 변수이름에는 '&'가 붙고, 매크로 이름에는 '%'가 붙습니다.
*조건식을 가진 매크로
%IF 조건문 %THEN 실행문;
-> 조건문에는 quotation marks가 필요 없습니다.
*SYSDAY: 자동 매크로 변수로 session 시작 요일
39. Which one of the following statements is true regarding a SAS DATA step view?
A. It allows write capabilities.
B. It contains global statements.
C. It contains data and a descriptor portion.
D. It contains a partially compiled DATA step.
[정답]D
[풀이]
SAS DATA Views는 데이터는 저장되지 않지만 저장된 프로그램을 담고 있는 데이터 파일의 일반화된 database개념으로 SAS코드가 저장됩니다.
실제의 데이터는 담고 있지 않지만, I/O를 줄이고, 데이터 공간을 줄이고 실제 시간을 줄여줍니다.
+ sas data file에는 데이터가 저장되어 있으며, 데이터 뷰에는 구조가 저장되어 있습니다.
*VIew 구조
data dept.a / view = dept.a;
.... more SAS statements...
run;
40. Given the following SAS data sets ONE and TWO:
[ONE Data]
OBS | COMMON | X |
1 | A | 10 |
2 | A | 13 |
3 | A | 14 |
4 | B | 9 |
5 | C | 8 |
6 | C | 14 |
[TWO]
OBS | COMMON | X |
1 | A | 1 |
2 | A | 3 |
3 | B | 4 |
4 | B | 2 |
5 | C | 5 |
The following SAS DATA step is submitted:
data combine;
merge one two;
by common;
run;
Which one of the following represents the data values stored in data set COMBINE?
A.
obs | common | X | Y |
1 | A | 10 | 1 |
2 | A | 13 | 3 |
3 | A | 14 | 3 |
4 | B | 9 | 4 |
5 | B | 9 | 2 |
6 | C | 8 | 5 |
7 | C | 14 | 5 |
B.
obs | common | X | Y |
1 | A | 10 | 1 |
2 | A | 13 | 3 |
3 | B | 9 | 4 |
4 | C | 8 | 5 |
C.
X | common | X | Y |
1 | A | 10 | 1 |
2 | A | 13 | 3 |
3 | B | 14 | 4 |
4 | B | 9 | 2 |
5 | C | 8 | 5 |
D.
X | common | X | Y |
1 | A | 10 | 1 |
2 | A | 13 | 1 |
3 | A | 14 | 1 |
4 | A | 10 | 3 |
5 | A | 13 | 3 |
6 | A | 14 | 3 |
7 | B | 9 | 4 |
8 | B | 9 | 2 |
9 | C | 8 | 5 |
10 | C | 14 | 5 |
[정답] A
[풀이]
merge문은 둘 이상의 sas 자료들을 관측별로 병합하여 새로운 sas자료를 만듭니다.
병합하는 자료들에 공통적인 변수가 있으면 이 공통변수를 BY문장에서 지정할 수 있습니다.
*MERGE SYNTAX
DATA sas-data-set;
MERGE sas-data-set(S); /*먼저 나오는 table이 master테이블이고, 그 다음 나오는 테이블이 transaction 테이블입니다. */
BY variable(s); /*정렬 되어야 합니다.*/
RUN;
*one-to-many, many-to-many, non-matches가 있다.
> one-to-many(일대다결합)
master table에서 unique하게 나타나틑 BY variable값과 Transaction table에서 여러 번 나타나는 BY variable값이 matching될 경우입니다.
> many-to-many merging
master table과 transaction table에서 여러 번 나타나는 BY variable값이 matching될 경우.
> Merging with non-matches
master table과 transaction table에서 BY variable 값의 일부 또는 전부가 non-matching되는 경우.
BY common으로 1:1매칭이 가능하지 않으면, 가장 최근에 1:1매칭에 성공한(=윗값)값을 복사합니다.
위 문제는 many-to-many merging으로 BY common에서 A값이 있는 one table과 two table을 살펴보면,
one table에는
1 A 10
2 A 13
3 A 14
two table에는
1 A 1
2 A 3
이 있습니다.
merge는 단순 가로결합으로 결과는
1 A 10 1
2 A 13 3
3 A 14 3(윗값 복사)이 됩니다.
그러므로, 매칭이 안되는 값은 바로 윗행을 복사합니다.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.