SAS Base, A00-211 Crambible 

SAS 베이스 자격증


QUESTION NO: 72


The SAS data set named WORK.SALARY contains 10 observations for each department, and is currently ordered by Department. 


The following SAS program is submitted:


data WORK.TOTAL;
set WORK.SALARY(keep=Department MonthlyWageRate);

by Department;

if First.Department=1 then Payroll=0; 

Payroll+(MonthlyWageRate*12);

if Last.Department=1;
run;



Which statement is true?

A. The by statement in the DATA step causes a syntax error.

B. The statement Payroll+(MonthlyWageRate*12); in the data step causes a syntax error.


C. The values of the variable Payroll represent the monthly total for each department in the WORK.SALARY data set.

D. The values of the variable Payroll represent a monthly total for all values of WAGERATE in the WORK.SALARY data set.


각 부서(department)별로 10개의 observations이 있고요. by를 이용해서 부서들이 정렬이 되어있습니다. 


이때 sas 코드를 보면, work 라이브러리에 있는 salary 데이터에서 keep을 이용해서 department, monthlywagerate 변수를 가져옵니다. 그리고 다시 by를 이용해서 department별로 오름차순으로 정렬하고요. (default값이 오름차순입니다) 


이렇게 set & by 에서 정렬이 되어있으면 각 부서마다 처음나오는 observation과 같은 부서의 마지막에 나오는 observation이 pdv상에 생기게 됩니다. 잘 모르시면 first/ last 문제 반복해서 나오고 있으니 확인해보세요. 


문제에서 각 부서마다 10개의 observation이 있다고 했으니 하나의 부서에서 첫번쨰 나오는 값이 first, 같은 부서 마지막에 나오는 값이 last라는걸로 표시가 되는거예요. 이 기능은 각 부서별로 wagerate을 누적해서 더한 값을 구하려고 할때 얘네들이 잘 활용이 됩니다. 


워낙 반복적으로 나오는 문제니까 다른문제 참고하시라 생각하면서~ 이만 줄일게요.  



Answer: C 


반응형

+ Recent posts