全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
2421 2
2016-07-09
19.A raw data file is listed below.
1---+----10---+----20---+--- 1901 2
1905 1
1910 6
1925 1 1941 1
The following SAS program is submitted and references the raw data file above:
data money;
infile 'file-specification'; input year quantity; total=total+quantity;
run;
What is the value of total when the data step finishes executing?
a. 0
b. 1
c. 11
d. .(missingnumericvalue)

Correct answer: d



47.The following SAS program is submitted: data work.travel;
   do i=1 to 6 by 2;
      trip + i;
end;
run;
Which one of the following is the value of the variable trip in the output data set?
a. 2
b. 3
c. 9
d. 10
Correct answer: c

The sum variable in a sum statement is automatically set to 0 before the first observation is read from the data set. The sum variable in the statement above is increased by the value of i on each iteration of the DO loop; the value of i is set to 1 on the first iteration of the DO loop and increases by 2 on each additional iteration until it is greater than 6. Therefore, the value ofTripis equal to 0 + 1 + 3 + 5, which is 9.

不是应该i=1,3,5吗?那个9 是怎么算出来的?
二维码

扫码加我 拉你入群

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

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

全部回复
2016-7-10 22:50:48
19. total=total+quantity实际上用了一个赋值语句assign statement,这个语句对数据没有reatin的功能,SAS会将所有变量设成缺失值。
如果你把这个赋值语句:total=total+quantity改为一个sum statement, 即 total+quantity,那么你就会得到你想要的结果11。这里的sum statement起到了非常大的作用:(1)有retain功能 (2)产生新的变量,此处为total (3)在每个观测上+quantity
如果你还是要用total=total+quantity, 则加一个retain total 0 你还是能得到结果11。你可以自己在系统中跑一遍

47. trip=trip+i=0+1+3+5=9这道题其实和刚才的19一样
二维码

扫码加我 拉你入群

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

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

2016-7-11 22:55:11
cindy2468 发表于 2016-7-10 22:50
19. total=total+quantity实际上用了一个赋值语句assign statement,这个语句对数据没有reatin的功能,SAS会 ...
谢谢回复!

明白了!
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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