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
Ans C
ReplyDeletec)1750 (1000+100+200+300+150)
ReplyDeleteans is C
ReplyDeleteAns is C
ReplyDeleteC it is.
ReplyDeletedata work.donations;
ReplyDeleteinput 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
donation_
DeleteObs qtr1 tot
1 100 1100
2 200 1300
3 300 1600
4 . 1600
5 150 1750
6 50 1800
data work.employee_donations;
Deleteinfile 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
C
ReplyDeleteIs it still C in sas 9?
ReplyDeletemissing + nonmissing = missing?
This comment has been removed by the author.
DeleteAnswer is C.
ReplyDeleteFirst 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.