全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
2926 2
2010-11-11
25.Given the following code:

proc print data=SASHELP.CLASS(firstobs=5 obs=15);
    where Sex='M';
run;

How many observations will be displayed?

     A. 11
     B. 15
     C. 10 or fewer
     D. 11 or fewer

Answer: D
本文属于博客:http://crackman.net/
版权归作者所有,欢迎转载!如有转载,请务必注明出处!未经本文作者同意不得用于商业应用。
本题考察的是firstobs以及obs两个参数的作用。
FIRSTOBS:确定读取观测的起始序列号,obs是确定读取观测终止时的序列号。也就是从第五个观测开始,到第15个观测时结束。
从第5和第15之间的数据有11个,第五和第十五的观测序号根据where的筛选后的数据集来确定的,例如,所以答案为D。
看看外文文献的解释:
Use the FIRSTOBS= and OBS= options together to process a set of observations from the middle of a data set. For example, this statement processes only observations 1000 through 1100:
options firstobs=1000 obs=1100;

感谢POBEL的补充!
二维码

扫码加我 拉你入群

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

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

全部回复
2010-11-11 16:27:10
支持Crackman版主,个人补充一点:

这个题还有一点需要注意,where语句是先执行的,firstobs= 和obs= 是作用在where语句的结果集上的(如本例的sex=“M”)。
而不是先找出数据集中的第5条至第15条记录,然后从这11条记录中找sex=“M”的。

例如:

输出sashelp.class的第2-5条记录,只有1条记录的sex="M"。

proc print data=sashelp.class(firstobs=2 obs=5);
run;

/**output;
Obs     Name      Sex    Age    Height    Weight
  2    Alice       F      13     56.5       84.0
  3    Barbara     F      13     65.3       98.0
  4    Carol       F      14     62.8      102.5
  5    Henry       M      14     63.5      102.5
*/


加上where语句后仍然会输出4条记录,而不是1条。

proc print data=sashelp.class(firstobs=2 obs=5);
  where sex="M";
run;

/*output
Obs    Name       Sex    Age    Height    Weight
   5    Henry       M      14     63.5      102.5
   6    James       M      12     57.3       83.0
   9    Jeffrey     M      13     62.5       84.0
  10    John        M      12     59.0       99.5
*/


题目中的选项D. 11 or fewer)中,fewer的情况只有在数据集中满足where条件的记录数小于obs=选项指定的数(本例15)时才会出现。
二维码

扫码加我 拉你入群

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

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

2010-11-11 17:14:05
谢谢probel的补充!
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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