02-25-2016 12:37 PM
The following SAS program is submitted and references the raw data file above:
input year quantity;
<insert statement(s) here>
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? (here quantity is the numbers 2,1,6,.,1 in the dataset)
A. totquantity + quantity;
B. totquantity = sum(totquantity + quantity);
C. totquantity 0;
D. retain totquantity 0;
totquantity = totquantity = quantity;
Doubt: As A is not in a SUM or RETAIN statement won't it cause missing value as '.'; or does this expression accumulates and retains the values?
02-25-2016 01:09 PM
This is called Sum Statment in SAS. And it is equivalent to using the SUM function and the RETAIN statement.
As you noticed in your data you have missing values so to do the cumulative summation you need the SUM function and Retain or as shortcut you can use the SUM statment.