全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
4993 8
2013-05-20
37. The SAS data set ONE contains fifty million observations and contains the variables PRICE, QUANTITY,
FIXED, and VARIABLE.
Which SAS program successfully creates three new variables TOTREV, TOTCOST, and PROFIT and requires the
least amount of CPU resources to be processed?
A.data two;
set one;totrev = sum(price * quantity);totcost = sum(fixed,variable);
if totrev > 1000;
profit = sum(totrev,-totcost);
run;
B.data two;
set one;
totrev = sum(price * quantity);
if totrev > 1000;
totcost = sum(fixed,variable);
profit = sum(totrev,-totcost);
run;

C.data two;
set one;
totrev = sum(price * quantity);
where totrev > 1000;
totcost = sum(fixed,variable);
profit = sum(totrev,-totcost);
run;

D.data two;
set one;
where totrev > 1000;
totrev = sum(price * quantity);
totcost = sum(fixed,variable);
profit = sum(totrev,-totcost);
run;

Answer: B
为什么是B 不是C啊





二维码

扫码加我 拉你入群

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

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

全部回复
2013-5-20 17:53:50
where语句在set语句之后执行,此时totrev不存在,程序错误不会执行。
二维码

扫码加我 拉你入群

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

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

2013-5-20 17:58:39
boe 发表于 2013-5-20 17:53
where语句在set语句之后执行,此时totrev不存在,程序错误不会执行。
where 放在run前面就可以了吧 where 是在input buffer前进行处理,就是说 totrev不存在是吧
二维码

扫码加我 拉你入群

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

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

2013-5-20 18:10:02
clark3721 发表于 2013-5-20 17:58
where 放在run前面就可以了吧 where 是在input buffer前进行处理,就是说 totrev不存在是吧
非也。where紧接着set执行,用来过滤数据,sas再执行其他语句。故where中的变量必须存在于现有数据集,而不是那种进一步计算得到的。
二维码

扫码加我 拉你入群

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

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

2013-5-20 18:29:20
boe 发表于 2013-5-20 18:10
非也。where紧接着set执行,用来过滤数据,sas再执行其他语句。故where中的变量必须存在于现有数据集,而 ...
我run了下发现where是对one进行筛选的,one里没有这个变量 这才是最主要的原因对吧
二维码

扫码加我 拉你入群

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

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

2015-11-5 03:11:21
WHERE statements work on variables that are already in SAS data sets.

run C, then you will get error message.

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.TWO may be incomplete.  When this step was stopped there were 0
         observations and 5 variables.
WARNING: Data set WORK.TWO was not replaced because this step was stopped.


二维码

扫码加我 拉你入群

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

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

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

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