The following SAS program is submitted:
data WORK.TOTAL_SALARY;
retain Total;
set WORK.SALARY;
by Department;
if First.Department
then Total=0;
Total=sum(Total, Wagerate);
if Last.Total;
run;
What is the initial value of the variable Total?
A. 0
B. Missing
C. The value of the first observations Wagerate
D. Cannot be determined from the information given
Answer: B
注解:The second line of codes, retain Total, initializes the variable Total. As it doesn’t specify an initial value, a missing value is assigned to the variable. Please also check SAS Base (32) for the details of RETAIN statement.
The answer is (b).
When no initial value is specified for the variable in the RETAIN statement, the variable is initiated with a missing value.
Like retain Total 0; then initial value of Total is 0. But in this case, there is no “0” so that it is missing value.