楼主: 棋子符号
2383 6

[问答] data步新建变量 [推广有奖]

  • 0关注
  • 0粉丝

初中生

80%

还不是VIP/贵宾

-

威望
0
论坛币
10 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
340 点
帖子
14
精华
0
在线时间
15 小时
注册时间
2013-10-24
最后登录
2015-11-18

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
有一组数据                        新建一组变量flag 输出为
id  score                                 id  score  flag
1  1.5                                     1   1.5
1  1.6                                     1   1.6
1  1.9                                     1   1.9     yes
2  1.3                                     2   1.3
2  1.4                                     2   1.4
2  1.4                                     2   1.4     yes

就是flag是按照id分组 当score为组内最大值时flag为yes 否则为空格,一组id里score有重复值时,在升序排列的最后一位记录yes。想在data步里编程应该怎么写?求帮助,谢谢!
二维码

扫码加我 拉你入群

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

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

关键词:data步 Data 新建变量 score core 新建

沙发
mingfeng07 学生认证  发表于 2014-4-16 15:47:08 |只看作者 |坛友微信交流群
  1. data a;
  2. input id  score;
  3. cards;
  4. 1  1.5                                    
  5. 1  1.6                                    
  6. 1  1.9                                    
  7. 2  1.3                                 
  8. 2  1.4                             
  9. 2  1.4     
  10. ;
  11. run;
  12. proc sort data=a;
  13. by id score;
  14. run;
  15. data b;
  16. set a;
  17. by id score;
  18. if last.id then flag='yes';
  19. run;
复制代码
欢迎扫一扫我头像关注, 不定期分享SAS技术知识。

使用道具

藤椅
wwang111 发表于 2014-4-16 15:48:50 |只看作者 |坛友微信交流群
data test;
input id score;
cards;
1  1.5
1  1.6
1  1.9
2  1.3
2  1.4
2  1.4
;

proc sort data=test;
by id score;
run;

data wanted;
set test;
by id score;
if last.id then socre='Y';
run;
只有一个罗纳尔多

使用道具

板凳
棋子符号 发表于 2014-4-16 15:53:58 |只看作者 |坛友微信交流群
mingfeng07 发表于 2014-4-16 15:47
非常感谢!

使用道具

报纸
棋子符号 发表于 2014-4-16 15:57:06 |只看作者 |坛友微信交流群
wwang111 发表于 2014-4-16 15:48
data test;
input id score;
cards;
非常感谢!

使用道具

地板
棋子符号 发表于 2014-4-16 16:12:55 |只看作者 |坛友微信交流群
mingfeng07 发表于 2014-4-16 15:47
你好~麻烦我还想在请教一下,如果这个score有重复值时,每个重复值后面都标记yes,要怎么写?谢谢!麻烦你了~

使用道具

7
mingfeng07 学生认证  发表于 2014-4-16 19:22:45 |只看作者 |坛友微信交流群
棋子符号 发表于 2014-4-16 16:12
你好~麻烦我还想在请教一下,如果这个score有重复值时,每个重复值后面都标记yes,要怎么写?谢谢!麻烦你 ...
  1. data a;
  2. input id  score;
  3. cards;
  4. 1  1.5                                    
  5. 1  1.6                                    
  6. 1  1.9                                    
  7. 2  1.3                                 
  8. 2  1.4                             
  9. 2  1.4     
  10. ;
  11. run;
  12. proc sql;
  13. create table b as select id ,score,max(score) as max from a group by id;
  14. quit;
  15. proc sort data=b;
  16. by id score;
  17. run;
  18. data c(drop=max);
  19. set b;
  20. by id score;
  21. if score=max then flag='yes';
  22. run;
复制代码
欢迎扫一扫我头像关注, 不定期分享SAS技术知识。

使用道具

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

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-27 14:11