Question : 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 WORK.SALARY, currently ordered by DEPARTMENT, contains 100 observations for each of 5 departments. Which one of the following represents how many observations the WORK.TOTAL data set contains?
Explanation: The most important statement in the program for this question is if last.department; We will get output only if last.department becomes true and we know there are five departments and data is sorted by department so last.department will become true 5 times and thus 5 observation in output.
Question : 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?
1. The BY statement in the DATA step causes a syntax error. 2. FIRST.DEPARTMENT and LAST.DEPARTMENT are variables in the WORK.TOTAL data set. 3. Access Mostly Uused Products by 50000+ Subscribers 4. The values of the variable PAYROLL represent a total for all values of WAGERATE in the WORK.SALARY data set.
Explanation: When first.department is true payroll is set to 0. So the accumulator for each department is reset to 0 before accumulating. 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 3
Question : The following SAS program is submitted: libname sasdata 'SAS-data-library'; data test; set sasdata.chemists (keep = job_code); if job_code = 'chem3' then description = 'Senior Chemist'; run; The variable JOB_CODE is a character variable with a length of 6 bytes. Which one of the following is the length of the variable DESCRIPTION in the output data set?
Explanation: Length of a variable is assigned during first assignement, in this case description = "Senior Chemist" which is 14 character long, so the new variable description will have lenght of 14. So answer is 3