楼主: cynthialam
2499 16

如何计量重复度? [推广有奖]

11
zhangzachary 发表于 2012-1-18 16:55:56 |只看作者 |坛友微信交流群
我调整了一下原数据aa,你只要用你的原数据,不过要记得交换排序:
  1. data aa;
  2.   set aa aa(rename=(a=b b=a));
  3. run;

  4. proc sort data=aa;
  5.   by a b;
  6. run;
复制代码
然后用后面的程序,res 就是你要的结果~
寒冰凤凰 My blog: http://blog.sina.com.cn/u/1058955485

使用道具

12
zhangzachary 发表于 2012-1-18 16:58:46 |只看作者 |坛友微信交流群
cynthialam 发表于 2012-1-18 13:54
重复度:对方编号的相同数量。
因为根据数据,2的对方编号为1、3、4,4号的对端编号为2、3;所以,2号和 ...
请注意11楼的补充,不要盲目套用程序,谢谢~
寒冰凤凰 My blog: http://blog.sina.com.cn/u/1058955485

使用道具

13
xiaosanmao 发表于 2012-1-19 10:09:59 |只看作者 |坛友微信交流群
  1. 如果对应关系不多 可以手抄一下咯
  2. data a;
  3. input a b;
  4. id=_n_;
  5. cards;
  6. 3 2
  7. 3 4
  8. 4 3
  9. 4 2
  10. 1 2
  11. 2 1
  12. 2 3
  13. ;
  14. run;

  15. data b;set a;call sortn(a,b);c=compress(a||b);
  16. if c="12" then flag=0;
  17. if c="13" then flag=0;
  18. if c="14" then flag=0;
  19. if c="23" then flag=1;
  20. if c="24" then flag=1;
  21. if c="34" then flag=1;
  22. keep id flag;run;
  23. data final;merge a b;by id;run;
复制代码

使用道具

14
maidenhan 发表于 2012-1-19 15:23:40 |只看作者 |坛友微信交流群
Let me share a way in array.

data test01;
        input a b;
        call sortn(a,b);
        output;
cards;
3 2
3 4
4 3
4 2
1 2
2 1
2 3
;run;
proc sort data = test01 nodupkey; by _all_; run;
data test02;
        set test01
                test01(rename=(b=a a=b));
        value = 1;
run;
proc sort data = test02; by a b;run;
proc transpose data = test02 out = test03(drop = _NAME_);
        id b;
        by a;
run;
proc sql noprint;
        select count(*) into:n from test03;
quit;
%let _end = %sysfunc(compress(_&n.));
data test04(keep = a b dup);
        format a b dup 8.;
        array m(&n.,&n.) _temporary_;
        array ra(*) _1-&_end.;
        do ii = 1 to &n.;
                set test03 point = ii;
                do jj = 1 to &n.;
                        m(ii,jj) = ra(jj);
                end;
        end;
        do ii = 1 to &n.;
                do jj = ii+1 to &n.;
                        dup = 0;
                        do kk = 1 to &n.;
                                dup = sum(dup, m(ii,kk)+m(jj,kk));
                        end;
                        dup = dup / 2;
                        a = ii;
                        b = jj;
                        output;
                end;
        end;
        stop;
run;

使用道具

15
cynthialam 发表于 2012-1-22 12:17:40 |只看作者 |坛友微信交流群
maidenhan 发表于 2012-1-19 15:23
Let me share a way in array.

data test01;
小数据量时,这种方法是可行的。可是,我有上百万的记录,在Tranpose这一步卡壳了......

使用道具

16
cynthialam 发表于 2012-1-22 12:18:48 |只看作者 |坛友微信交流群
zhangzachary 发表于 2012-1-18 16:52
那个
%macro chongfu;

  %do i=1 %to &N. ;

    if  index(chain_b,substr(chain,&i.,1)) and substr(chain,&i.,1) ne " " then cf+1;

  %end;

%mend;
这个宏不是特别理解....

使用道具

17
Kalet 在职认证  发表于 2012-1-22 13:37:07 |只看作者 |坛友微信交流群
为啥2:1,3,4?你的DATA步中a=2只有两行。
我猜测你少写了一行2 4

data aa;
  input a b;
  cards;
3 2
3 4
4 3
4 2
1 2
2 1
2 3
2 4
  ;
run;
zhangzachary 的code已经解决问题了。剩下的就是优化代码效率了。
那个宏的意思是先对a的对方编号扫描,找找到一个就去b的对方编号找有没有,有就+1。



使用道具

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

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

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

GMT+8, 2024-5-22 04:53