全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
3330 4
2008-04-21
Question: 1The SAS data set TEMP has the following distribution of values for variable A:

A
Frequency
1
500,000
2
500,000
6
7,000,000
8
3,000

Which one of the following SAS programs requires the least CPU time to be processed?

A.data new; set temp;
if a = 8 then b = 'Small ';
else if a in(1, 2) then
b = 'Medium';
else if a = 6 then
b = 'Large'; run;

B. data new;
set temp;
if a in (1, 2) then
b = 'Medium';
else if a = 8 then
b = 'Small';
else if a = 6 then
b = 'Large'; run;

C. data new;
set temp;
if a = 6 then b = 'Large ';
else if a in (1, 2) then
b = 'Medium';
else if a = 8 then
b = 'Small';

D. data new;
set temp;
if a = 6 then
b = 'Large ';
if a in (1, 2) then
b = 'Small';  run;

Answer: C Q2.
which one of the following SAS program successfully creates three new variables TOTREV, TOTCOST, and FROFIT and requried the least CPU time to be precessed?



data two;
set one;


totrev = sum (price *quantity);


totcost = sum (fixed, variable);


profit = sum (totrev,otcost);


if totrev>1000;


run;





data two;
set one;


totrev = sum (price *quantity);


if totrev>1000;


totcost = sum (fixed, variable);


profit = sum (totrev,otcost);


run;





data two;
set one;


totrev = sum (price *quantity);


where totrev>1000;


totcost = sum (fixed, variable);


profit = sum (totrev,otcost);


run;





data two;
set one;


where totrev>1000;


totrev = sum (price *quantity);


totcost = sum (fixed, variable);


profit = sum (totrev,otcost);


run;





Answer: B


请大家帮忙分析一下。谢谢。

[此贴子已经被angelboy于2008-4-24 14:35:45编辑过]

二维码

扫码加我 拉你入群

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

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

全部回复
2008-4-22 00:40:00

第一题,C没有run;程序没有运行不占用时间吧。

第二题,C,D语法错误,A需要先计算完totcost = sum (fixed, variable);

profit = sum (totrev,otcost); 才if, 运行时间应该比B长。

个人意见哦

二维码

扫码加我 拉你入群

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

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

2008-4-22 03:18:00

Question 1:

if/then/else-->The most efficient way: Check the most frequently occurring condition first, and continue checking conditions in descending order of frequency.

 

Question 2:

A WHERE statement tests the condition before an observation is read into the SAS program data vector (PDV). Hence C and D is wront 'coz variable totrev does not exist before it is processed and created.

 

B is more efficient than A 'coz in B the if-statement is put on the top which means that the if statement process less data.

 


二维码

扫码加我 拉你入群

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

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

2008-4-22 11:08:00
谢谢两位的高见。收益匪浅。
二维码

扫码加我 拉你入群

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

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

2009-9-12 07:14:42
三楼回答的精辟,赞!
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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