全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1951 2
2011-12-21
有道题是:
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.

似乎解释不一样,这两题难道有什么不同之处?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2011-12-21 15:30:10
记住:
sum对缺省值进行处理
加号不对缺省值进行处理

sum(Amount+AdditionalItems)+200
先算Amount+AdditionalItems, 加号中有缺省值,则该结果为缺省值
然后 .+200 结果为缺省值

sum (OrigPassengers, TransPassengers);
sum能对缺省值进行处理,所以能得到值

搞清楚sum的语法结构,中间是逗号
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2011-12-21 21:53:07
myccc 发表于 2011-12-21 15:30
记住:
sum对缺省值进行处理
加号不对缺省值进行处理
哦,
多谢了,
才发现上面那个sum里面是(amount+additionalitem)

那如果是sum(amount, additionalitem)结果就不同了,这个就能ignore missing ,得到数值了
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群