SAS Base Certification – Question 7

Question 7: This item will ask you to provide a line of missing code;
 
The SAS data set WORK.INPUT contains 10 observations, and includes the numeric variable Cost.
 
The following SAS program is submitted to accumulate the total value of Cost for the 10 observations:
 

1
2
3
4
5
data WORK.TOTAL;
  set WORK.INPUT;
  <insert code here>
  Total=Total+Cost;
run;

Which statement correctly completes the program?
 
Options:

A.	keep Total;
B.	retain Total 0;
C.	Total = 0;
D.	If _N_= 1 then Total = 0;

*The SAS certification sample problem and answer above are sourced from the official SAS sample questions page. All answer logs, data sets, output, and commentary are provided by this blog.

Correct Answer

Incorrect Answer

Click to see Answer Explanation below

thanks for your support

6 Comments

    Ashley Hill Oct 14, 2015

    I didn’t think retain was needed with a sum statement like Total=Total+Cost;
    Am I wrong?

    Reply
      mcypert16 Feb 29, 2016

      I believe if it was total+cost it works, but it is total=total+cost

      Reply
    Kesu Kaltol Dec 05, 2015

    I think both options b and c works.Please response my quarry.Thank you.

    Reply
    Andy Perloy Dec 10, 2016

    To Ashley: The retain function is redundant if you assign a value to a variabele in a sum statement (‘total+0’). Thus, you could have skipped the retain function using the following program:

    data WORK.TOTAL;
    set WORK.INPUT;
    Total+0;
    Total=Total+Cost;
    run;

    Reply
      Andy Perloy Dec 10, 2016

      Or even easier.

      data WORK.TOTAL;
      set WORK.INPUT;
      Total+Cost;
      run;

      Reply
    ishmo65 Jun 16, 2017

    Total+0 is inefficient as it will be executed once for every observation – Andy Perloy’s solution or the answer in the question are the best ways to achieve the outcome required

    Reply

Leave a Comment

Please keep in mind that comments are moderated and rel="nofollow" is in use. So, please do not use a spammy keyword or a domain as your name, or it will be deleted. Let us have a personal and meaningful conversation instead.