楼主: pussqr
2897 11

[原创博文] 求助合并数据集 [推广有奖]

11
shenliang_111 发表于 2011-9-13 13:30:31
  1. /*try with hash*/
  2. data a;

  3. input / id $ x1 x2 x3;

  4. cards;

  5. 1      8     20   3

  6. 3      3     0     8

  7. 4      2     4     0

  8. ;

  9. data b;

  10. input / id $ x1 x2 x3;

  11. datalines;

  12. 1    0     7    3

  13. 4    9    0     5

  14. 5    8    5     9

  15. ;

  16. data _null_;
  17. if 0 then set a;
  18. if _n_=1 then do;
  19. declare hash h(dataset:'a',ordered:'y');
  20. h.definekey('id');
  21. h.definedata('id','x1','x2','x3');
  22. h.definedone();
  23. end;
  24. set b(rename=(x1=xx1 x2=xx2 x3=xx3))   end=last;
  25. rc=h.find();
  26. if rc=0 then do;
  27. x1+xx1;
  28. x2+xx2;
  29. x3+xx3;
  30. h.replace();
  31. end;
  32. else do;x1=xx1;x2=xx2;x3=xx3;h.add();end;
  33. if last then h.output(dataset:'result');
  34. run;
复制代码

12
anniegirl 发表于 2011-10-29 20:59:13
学习了,很好

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

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