ElearnSAS.com

ElearnSAS.com
SAS Learning Platform

Base SAS 53

Base SAS

The following SAS program is submitted:
data work.total;
set work.salary(keep = department wagerate);
by department;
if first.department then payroll = 0;
payroll + wagerate;
if last.department;
run;
The SAS data set named WORK.SALARY contains 10 observations for each department, currently ordered by DEPARTMENT.
Which one of the following is true regarding the program above?
A. The BY statement in the DATA step causes a syntax error.
B. FIRST.DEPARTMENT and LAST.DEPARTMENT are variables in the WORK.TOTAL data set.
C. The values of the variable PAYROLL represent the total for each department in the WORK.SALARY data set.
D. The values of the variable PAYROLL represent a total for all values of WAGERATE in the WORK.SALARY data set.
Click Comment link to get answer
Click Comment link to get answer

13 comments:

  1. Anonymous2:54 AM

    D??

    ReplyDelete
  2. I think both C and D are correct..
    Cud anybdy please tell the correct answer

    ReplyDelete
    Replies
    1. Robert B.1:00 PM

      Not D because when first.department is true payroll is set to 0. So the accumulator for each department is reset to 0 before accumulating.

      Delete
    2. Anonymous2:23 AM

      gadhe ki potty

      Delete
  3. Correct answer is C. when you use PAYROLL + WAGERATE, variable payroll will automatically be retained through-out the dataset. Its values is resetted at first observation of each department. The observations to output dataset total are output on last observation of each department. So number of observation in total dataset are number of departments in salary dataset. Moreover wagerate is getting added to payroll and that value is retained in payroll variable untill the next observation of same department is read. After that second observations wagerate gets added to payroll, so on and so forth untill all the 10 observations are read for a department. At last observation, payroll has the sum of all wagerate for that particular department and is outputed to total dataset. Hence answer is C.

    ReplyDelete
  4. Anonymous11:05 AM

    Exactly Sascert

    ReplyDelete
  5. Anonymous12:53 PM

    cheers sascert !

    ReplyDelete
  6. Anonymous4:14 PM

    Excellent explanation sascert. Thanks a lot

    ReplyDelete