By admin | September 22, 2009

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;

6 comments | Add One

  1. admin - 09/22/2009 at 11:07 am

    A

  2. J - 01/25/2011 at 6:03 pm

    Answer D will produce zero for all observations. The question is only asking non-missing value. So, why not “D” ?

  3. sameer - 04/21/2011 at 7:49 am

    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

  4. jie - 03/2/2012 at 8:38 pm

    should be A, in this form the value of totquantity is automatically initialized to 0. do not need retain.

  5. sdelli - 01/5/2013 at 12:20 pm

    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.

  6. hh - 02/19/2014 at 9:45 am

    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.

Leave a Comment

Leave a Reply

Your email address will not be published.