Multiple choice technology programming languages

Input data is provided: squash 1.10 apples 2.25 juice 1.69 The following SAS program is submitted using the raw data file above: data groceries; infile 'file-specification'; input item $ cost; ---------------- run; Which one of the following completes the program and produces a grand total for all COST values?

  1. grandtot = sum cost

  2. grandtot = sum(grandtot,cost)

  3. retain grandtot 0;grandtot + cost;

  4. grandtot = grandtot+ cost

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

To accumulate a running total across observations, use a RETAIN statement to initialize the variable and preserve its value, then use the SUM statement syntax 'grandtot + cost;'. The RETAIN statement initializes grandtot to 0 and keeps its value between iterations, while '+ cost' adds each new cost value. Options A and B use incorrect SUM function syntax, and D lacks the necessary RETAIN.