有道题是:
data work.count;
if Amount=. then Amount=0;
AdditionalItems=100;
Amount=.;
TotalCount=sum(Amount+AdditionalItems)+200;
run;
What is the value of the TotalCount variable in the output data set?
Correct answer: d
a. 0
b. 200
c. 300
d. . (missing numeric value)
解释说:
sum of a missing value is missing. add 200 to that and you still have a missing value.
但是 123中有一题
The following SAS program is submitted:
data work.passengers;
if OrigPassengers = . then
OrigPassengers=100;
TransPassengers= 100;
OrigPassengers= .;
NonPaying= 10;
TotalPassengers= sum (OrigPassengers, TransPassengers);
run;
Which one of the following is the value of the TOTALPASSENGERS variable in the
output data set?
A. 100
B. 110
C. 200
D. . (missing numeric value)
Answer: A
解释说:PDV initializes all variables in data step to missing first. So if statement yields
true, so value of origpassenger becomes 100. Then transpassenger is assigned value
of 100. Next step value of origpassenger is overwritten with missing value. So when
you add using sum function which ignores missing value, values of orignpassenger and
transpassenger ie sum(.,100) gives you 100.
似乎解释不一样,这两题难道有什么不同之处?