楼主: tianlai888
1531 3

[问答] 请教:删除数据集中的观测? [推广有奖]

  • 0关注
  • 0粉丝

本科生

19%

还不是VIP/贵宾

-

威望
0
论坛币
46 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
540 点
帖子
44
精华
0
在线时间
57 小时
注册时间
2009-1-9
最后登录
2012-5-18

楼主
tianlai888 发表于 2012-2-15 11:42:17 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
请教:删除数据集中的观测?
       从数据集A中查找有数据集B的相等观测,然后删除。我是用下列程序:
data a;
input x y z;
cards;
1 2 3
5 4 3
6 9 8
;
run;

data b;
input x y;
cards;
1 3
5 4
;
run;  

proc sql;
create table c as
select * from a
where not exists
(select * from b where a.x=b.x  or  a.y=b.y);
quit;

由于A,B的观测非常多(几百万,变量也很多),运行非常慢。
请教高人;有没有其他速度快的办法?  我的版本SAS9.1
谢谢!!

二维码

扫码加我 拉你入群

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

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

关键词:数据集 proc sql Select Create cards

沙发
yunqingwang 在职认证  发表于 2012-2-15 12:05:09
内存大的话hash应该会快点,来学习学习

藤椅
shenliang_111 发表于 2012-2-15 15:22:17
  1. data a;
  2. input x y z;
  3. cards;
  4. 1 2 3
  5. 5 4 3
  6. 6 9 8
  7. ;
  8. run;

  9. data b;
  10. input x y;
  11. cards;
  12. 1 3
  13. 5 4
  14. ;
  15. run;
  16. /*抛个砖--期待更好的方法- */
  17. data _null_;
  18. if 0 then set a;
  19. if _n_=1 then do;
  20. declare hash h(dataset:'a');
  21. h.definekey('x');
  22. h.definedata('x','y','z');
  23. h.definedone();
  24. end;
  25. set b end=last;
  26. rc=h.find();
  27. if rc=0 then h.remove();
  28. if last then
  29. h.output(dataset:'aa');
  30. run;
  31. data _null_;
  32. if 0 then set aa;
  33. if _n_=1 then do;
  34. declare hash h(dataset:'aa');
  35. h.definekey('y');
  36. h.definedata('x','y','z');
  37. h.definedone();
  38. end;
  39. set b end=last;
  40. rc=h.find();
  41. if rc=0 then h.remove();
  42. if last then
  43. h.output(dataset:'result');
  44. run;
复制代码

板凳
shenliang_111 发表于 2012-2-15 15:47:36
  1. /*如果有多个key的话,可以用宏*/
  2. %macro hash(dsn,key,out);
  3. proc contents data=&dsn. out=out1(keep=name) noprint;
  4. run;
  5. proc sql noprint;
  6. select quote(strip(name)) into :variables separated by ','
  7. from out1;
  8. quit;
  9. %put &variables;
  10. proc delete data=out1;
  11. run;
  12. data _null_;
  13. if 0 then set &dsn.;
  14. if _n_=1 then do;
  15. declare hash h(dataset:"&dsn.");
  16. h.definekey("&key");
  17. h.definedata(&variables.);
  18. h.definedone();
  19. end;
  20. set b end=last;
  21. rc=h.find();
  22. if rc=0 then h.remove();
  23. if last then
  24. h.output(dataset:"&out");
  25. run;
  26. %mend hash;
  27. %macro remove();
  28.   %hash(a,x,temp);
  29.   %hash(temp,y,result);
  30.   proc delete data=temp;
  31.   run;
  32. %mend;
  33. %remove
复制代码

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

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