Wednesday, April 17, 2013

Base SAS Certification Example Question 10.1

Assume ecsql1.employee_donations has 6 observations, and qtr1 has 6 values listed below:

100
200
300
.
150
50


What is the value of donation_tot after the 5th DATA step iteration?


data work.donations;
     set ecsql1.employee_donations (drop=qtr2-qtr4);
     retain donation_tot 1000;
     donation_tot + qtr1;
run;


a) 0
b) 750
c) 1750
d) Data step fails due to errors


*******************************************

Leave your answers as a comment below...good luck!

-SAS Cert

12 comments:

  1. c)1750 (1000+100+200+300+150)

    ReplyDelete
  2. data work.donations;
    input qtr1 ;
    retain donation_tot 1000;
    donation_tot + qtr1;
    datalines;
    100
    200
    300
    .
    150
    50
    ;
    run;
    proc print data=work.donations;
    run;



    data work.donations;
    input qtr1 ;
    retain donation_tot 1000;
    donation_tot + qtr1;
    datalines;
    100
    200
    300
    .
    150
    50
    ;
    run;
    proc print data=work.donations;
    run;




    so ans is C

    ReplyDelete
    Replies
    1. donation_
      Obs qtr1 tot

      1 100 1100
      2 200 1300
      3 300 1600
      4 . 1600
      5 150 1750
      6 50 1800

      Delete
    2. data work.employee_donations;
      infile datalines;
      input qtr1;
      datalines;
      100
      200
      300
      .
      150
      50
      ;
      run;
      proc print data=work.employee_donations;
      run;

      Obs qtr1

      1 100
      2 200
      3 300
      4 .
      5 150
      6 50


      data work.emp_donations;
      set work.employee_donations;
      retain donation_tot 1000;
      donation_tot + qtr1;
      run;

      proc print data=work.emp_donations;
      run;

      donation_
      Obs qtr1 tot

      1 100 1100
      2 200 1300
      3 300 1600
      4 . 1600
      5 150 1750
      6 50 1800



      Delete
  3. Is it still C in sas 9?
    missing + nonmissing = missing?

    ReplyDelete
  4. Answer is C.


    First imports set with all six observations but drops variables qtr2, qtr3, qtr4 (never written PDV).

    Then retain statement initializes the variable donation_tot with a value of 1000.

    First iteration:
    sum statement using initialized value of 1000 for donation_tot and adds the value of qtr1 for this observation which is 100 so donation_tot = 1000 + 100 = 1100.


    Second iteration:
    Retain doesn't reset value of donation_tot. It just retaines value from iteration before.
    sum 1100 + qtr1 so 1100 + 200 = 1300.

    Third iteration:
    Retain value of donation_tot from before and add value of qtr1 for this observation.
    So 1300 + 300 = 1600


    Fourth iteration:
    Retain value of donation_tot from before and add value of qtr1 for this observation.
    So 1600 + missing = 1600 (sum statement ignores missing values).

    Fifth iteration:
    Retain value of donation_tot from before and add value of qtr1 from this observation.
    So 1600 + 150 = 1750.

    Sixth iteration:
    Retain value of donation_tot from before and add value of qtr1 from this observation.
    So 1750 + 50 = 18000.

    ReplyDelete