SAS Certified Base Programmer 123 Questions (70)
A raw data file is listed below:
----|----10---|----20---|----30 1901 2 1905 1 1910 6 1925 . 1941 1
The following SAS program is submitted and references the raw data file above:
data coins; infile'file-specification'; input year quantity; <insert statement(s) here> run;
Which one of the following completes the program and produces a non-missing value for the variable TOTQUANTITY in the last observation of the output data set?
A.
totquantity + quantity;
B.
totquantity = sum(totquantity + quantity);
C.
totquantity 0;
sum totquantity;
D.
retain totquantity 0;
totquantity = totquantity = quantity;
Topics:
SAS Base Questions |
6 Comments »
A
Answer D will produce zero for all observations. The question is only asking non-missing value. So, why not “D” ?
option D should be-
retain totquantity 0;
totquantity = totquantity +quantity;
and this should be the correct answer ,retain staement is required as the variable hasn’t been referred before
should be A, in this form the value of totquantity is automatically initialized to 0. do not need retain.
Answer A is correct. Answer D is not correct because the assignment statament (totquantity=totquantity+quantity) results in a missing value for totquantity in the fourth observation due to the missing value for quantity. The retain statement does not ignore the missing values but only retains the value for the variable.
According to SAS textbook,
sum statement
variable + expression
If the expression produces a missing value, the sum statement ignores it. So A is correct.
However, assignment statement assign a missing value if the expression produces a missing value. So D is incorrect.