全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
3154 5
2012-11-04
一道备考题

  To create a dataset with unique values of   

  a given varible using a data step and the   

  FIRST. and LAST. varaibales, it is assumed   

  that the input dataset is:   

     A.

sorted on that variable.


     B.

indexed by that variable.


     C.

naturally in order.     


     D.

any of the above A, B, or C


参考答案是A . 可是我使用以下测试程序,感觉B也是可以的.求高人帮忙解释

data test;

input  x  y $ @;

datalines;

5  china

3  japan

7  america

5  france

2  korea

2  british

;

run;


data out;

  set test;

  if first.x ;

run;

上述第二段程序在未sort或建立index时会报错,因此C, D都错.

关键是,用以下代码建立index后,上面的第二段程序执行成功,结果也正确.

prog sql;

  create index x on work.test;

quit;


请各位高手指点迷津.谢谢!

二维码

扫码加我 拉你入群

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

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

全部回复
2012-11-8 09:59:55
建index之后x就显示已排序状态了,但根本上还是因为需要x有序
二维码

扫码加我 拉你入群

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

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

2012-11-10 11:39:12
多谢楼上的回复.
感觉还是有些问题.建立index 后用proc contents 查看sort状态,显示为no, 这个跟楼上的回复似乎不一致.
而用proc sort后其sort状态就是yes了.

顺便说一下, 第二段程序写的有点问题,下面才是正确的.
data out;
  set test;
  by x;
  if first.x ;
run;
二维码

扫码加我 拉你入群

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

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

2012-11-13 05:25:35
"sorted on that variable" equal to that variable is in order, but you can do this by creating index or using proc sort.   
二维码

扫码加我 拉你入群

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

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

2012-11-15 19:01:44
lqyrendajinji 发表于 2012-11-13 05:25
"sorted on that variable" equal to that variable is in order, but you can do this by creating index  ...
Thank you for the reply
二维码

扫码加我 拉你入群

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

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

2013-3-24 21:59:22
我感觉应该选择 D
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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