楼主: Shirubei
3125 5

unique values using First.var and Last.var [推广有奖]

  • 0关注
  • 0粉丝

高中生

32%

还不是VIP/贵宾

-

威望
0
论坛币
0 个
通用积分
0
学术水平
0 点
热心指数
1 点
信用等级
0 点
经验
151 点
帖子
20
精华
0
在线时间
29 小时
注册时间
2012-9-6
最后登录
2020-11-29

楼主
Shirubei 发表于 2012-11-4 17:37:14 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
一道备考题

  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;


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

二维码

扫码加我 拉你入群

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

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

关键词:values unique Using First value values

沙发
voyagevio 发表于 2012-11-8 09:59:55
建index之后x就显示已排序状态了,但根本上还是因为需要x有序

藤椅
Shirubei 发表于 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;

板凳
lqyrendajinji 发表于 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.   

报纸
Shirubei 发表于 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

地板
Kalet 在职认证  发表于 2013-3-24 21:59:22
我感觉应该选择 D

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-13 01:25