楼主: uuuuknow
4608 5

[问答] 【请教】sas如何删除不符合条件的观测值 [推广有奖]

  • 0关注
  • 0粉丝

等待验证会员

高中生

22%

还不是VIP/贵宾

-

威望
0
论坛币
0 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
138 点
帖子
12
精华
0
在线时间
24 小时
注册时间
2015-4-15
最后登录
2017-8-9

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
idstatusamountclass

1

normal

1

n

1

normal

1

n

1

normal

1

n

2

normal

1

n

2

abnormal

1

n

3

abnormal

1

n

3

unusual

1

n

3

normal

1

n

3

abnormal

1

n

4

normal

1

n

4

normal

1

n
我有一个大致是上述这样的数据集,如果status不是normal 我就想删除整个id 例如id=2和3里的status存在abnormal 和unusual 我需要删除整个id 2和3 该怎么做呢? 求路过的大神指点一下 谢谢!!
二维码

扫码加我 拉你入群

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

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

关键词:观测值 abnormal unusual normal status sas 删除 观测 大神 路过

沙发
foocares 发表于 2017-5-4 11:41:07 |只看作者 |坛友微信交流群
读你的数据集进来的时候把where选项用上。
set yourdata(where=(status='normal'));

假如换成是用proc sql来实现, 那么

proc sql;
      select * from yourdataset
             where status = 'normal'
       ;
quit;

最基本的筛选操作呀兄弟

使用道具

藤椅
uuuuknow 发表于 2017-5-4 12:20:25 |只看作者 |坛友微信交流群
foocares 发表于 2017-5-4 11:41
读你的数据集进来的时候把where选项用上。
set yourdata(where=(status='normal'));
不对 你这样 id2和3里的normal也会被保存下来 我的意思是只要该id有一个状态不是normal 我就删除该id全删了

使用道具

板凳
priss111 发表于 2017-5-4 15:34:33 |只看作者 |坛友微信交流群
  1. data aa;
  2.         input id  status $ amount class $;
  3. cards;
  4. 1        normal        1        n
  5. 1        normal        1        n
  6. 1        normal        1        n
  7. 2        normal        1        n
  8. 2        abnormal        1        n
  9. 3        abnormal        1        n
  10. 3        unusual        1        n
  11. 3        normal        1        n
  12. 3        abnormal        1        n
  13. 4        normal        1        n
  14. 4        normal        1        n
  15. ;
  16. run;

  17. data aa1;
  18.         set aa;
  19.         if status^="normal" then output aa1;
  20. run;

  21. data aa1_;
  22.         set aa1;
  23.         flag="flag";
  24. run;
  25. proc sort data=aa out=aasort;
  26.         by id;
  27. proc sort data=aa1_ out=aa1_sort;
  28.         by id;
  29. run;

  30. data aaN(keep=id status amount class);
  31.         merge aasort aa1_sort;
  32.         by id;

  33.         if flag="";
  34. run;
复制代码

使用道具

报纸
l12345q 发表于 2017-5-4 16:43:40 |只看作者 |坛友微信交流群
简单:
proc sql;
      select * from table
             where  id not in (select distinct id from table where status <> 'normal')
       ;
quit;

使用道具

  1. data aa;
  2.   input id status $ amount class $;
  3. cards;
  4. 1        normal        1        n
  5. 1        normal        1        n
  6. 1        normal        1        n
  7. 2        normal        1        n
  8. 2        abnormal      1        n
  9. 3        abnormal      1        n
  10. 3        unusual       1        n
  11. 3        normal        1        n
  12. 3        abnormal      1        n
  13. 4        normal        1        n
  14. 4        normal        1        n
  15. ;
  16. run;

  17. proc sort data=aa out=aa_1(keep=id) nodupkey;
  18.         by id;
  19.         where status ne 'normal';
  20. run;

  21. data aa_2;
  22.         merge aa(in=a) aa_1(in=b);
  23.         by id;
  24.         if a and not b;
  25. run;
复制代码

使用道具

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

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

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

GMT+8, 2024-4-19 12:41