楼主: edragon1983
4678 18

[有偿编程] 如何从大数据判断变量是否相同 [推广有奖]

11
Tigflanker 发表于 2015-11-26 22:16:56
  1. data have;
  2.   a=1;s=1;d=1;
  3. run;

  4. proc sql noprint;
  5.   select name into: name separated by ' '
  6.   from dictionary.columns
  7.   where memname='HAVE'
  8.   ;
  9. quit;

  10. %let prx = %sysfunc (prxparse(s/(\w+)/new_\1/));
  11. %let new = %sysfunc (prxchange(&prx.,-1., %bquote(&name.)));

  12. %let prx = %sysfunc (prxparse(s/(\w+)/\1 = new_\1/));
  13. %let rename = %sysfunc (prxchange(&prx.,-1., %bquote(&name.)));

  14. %put &name;
  15. %put array new $ &new;
  16. %put rename = (&rename.);
复制代码

12
teqel 发表于 2015-11-27 00:30:54
不明白楼主的意思。是不是只要X2-X10中间有一个和X1不同,就让X1=1?

13
Tigflanker 发表于 2015-11-27 08:48:04
  1. data want_x;
  2.   set have;

  3.   array flag f_a f_s f_d;
  4.   array orig $ a s d;
  5.   array comp $ a1 s1 d1;

  6.   do i = _n_ + 1 to 4;
  7.     set one(rename = (a=a1 s=s1 d=d1)) point = i;
  8.         compare = catx('-',_n_,i);
  9.         do over flag;
  10.       flag = ~compare(orig,comp);
  11.         end;
  12.         output;
  13.   end;

  14.   drop a1 s1 d1 a s d i id;
  15. run;
复制代码
Try This!!

14
edragon1983 发表于 2015-11-27 11:04:11
teqel 发表于 2015-11-27 00:30
不明白楼主的意思。是不是只要X2-X10中间有一个和X1不同,就让X1=1?
单纯看x1,不同记录之间比较
x1-x10之间没关系,相当于repeat10次

15
edragon1983 发表于 2015-11-27 11:06:02
Tigflanker 发表于 2015-11-27 08:48
Try This!!
谢谢指导!我再试试

16
teqel 发表于 2015-11-27 11:16:06
edragon1983 发表于 2015-11-27 11:04
单纯看x1,不同记录之间比较
x1-x10之间没关系,相当于repeat10次
100万条记录两两比较,全部记下来,那不是要10^16?

17
木叶知秋 发表于 2015-11-27 14:50:15
试下proc compare,不确定能否加快计算速度
  1. data test;
  2. input id (x1-x4)($);
  3. cards;
  4. 1 a b c d
  5. 2 c b a d
  6. 3 c b a d
  7. 4 e c b a
  8. ;
  9. run;

  10. %macro comp;
  11. %if %sysfunc(exits(result)) ne 0 %then %do;
  12.         proc datasets lib=work nolist;
  13.         delete result;
  14.         quit;
  15. %end;
  16. data result;
  17. length x1-x4 $8 note $8;
  18. stop;
  19. run;
  20. %do i=1 %to 4;
  21.         %do j=%eval(&i.+1) %to 4;
  22.                 proc compare base=test(firstobs=&i. obs=&i.) compare=test(firstobs=&j. obs=&j.) noprint out=temp;
  23.                 var x1-x4;
  24.                 with x1-x4;
  25.                 run;
  26.                 data temp;
  27.                 set temp(keep=x1-x4);
  28.                 note="&i.--&j.";
  29.                 run;
  30.                 proc append base=result data=temp force;run;
  31.         %end;
  32. %end;
  33. %mend;
  34. %comp
复制代码

18
edragon1983 发表于 2015-11-27 18:12:44
teqel 发表于 2015-11-27 11:16
100万条记录两两比较,全部记下来,那不是要10^16?
是的,10^14/2

19
edragon1983 发表于 2015-11-27 22:33:38
木叶知秋 发表于 2015-11-27 14:50
试下proc compare,不确定能否加快计算速度
程序跑不了啊

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

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