楼主: 小鳄鱼a
1428 5

求高手帮助 [推广有奖]

  • 6关注
  • 10粉丝

学科带头人

3%

还不是VIP/贵宾

-

威望
0
论坛币
125 个
通用积分
0.0040
学术水平
40 点
热心指数
45 点
信用等级
43 点
经验
32801 点
帖子
1185
精华
0
在线时间
1539 小时
注册时间
2009-7-16
最后登录
2018-10-5

100论坛币
计算重合

重叠.xlsx

11.61 KB

重叠.xlsx

11.98 KB

最新的示范例子

关键词:求高手

回帖推荐

yongyitian 发表于6楼  查看完整内容

沙发
greenzh198 发表于 2015-5-4 21:38:28 |只看作者 |坛友微信交流群
sorry, i would like to help you i couldn't.

使用道具

藤椅
learsaas 发表于 2015-5-6 12:41:55 |只看作者 |坛友微信交流群
给你个sql的比较傻的方法,好的方法我自己留着,呵呵。
proc sql noprint;
        create table table_n as
                select time,id,code,count(distinct sd) as n from a group by time,id,code;
        create table table_b as
                select t1.time,t1.id,t1.code as code_s,t2.code as code_e
                from table_n t1,table_n t2
                where t1.time=t2.time and t1.id=t2.id and t1.code<t2.code;
        create table table_c as
                select t1.time,t1.id,t1.code_s,t1.code_e,t2.sd
                from table_b t1 left join a t2
                on t1.time=t2.time and t1.id=t2.id and (t2.code=t1.code_s or t2.code=t1.code_e);
        create table table_m as
                select time,id,code_s,code_e,count(distinct sd) as m label='总个数' from table_c group by time,id,code_s,code_e;
        create table table_m as
                select t1.*,t2.n as n1
                from table_m t1 left join table_n t2
                on t1.time=t2.time and t1.id=t2.id and t1.code_s=t2.code;       
        create table table_m as
                select t1.*,t2.n as n2,(t2.n+t1.n1-t1.m)/t1.m as chl label='重合率'
                from table_m t1 left join table_n t2
                on t1.time=t2.time and t1.id=t2.id and t1.code_e=t2.code;       
        create table table_clp as
                select time,id,code_s,code_e,avg(chl) as clp
                from table_m
                group by time,id,code_s,code_e;
quit;
已有 1 人评分论坛币 学术水平 信用等级 收起 理由
小鳄鱼a + 5 + 2 + 2 精彩帖子

总评分: 论坛币 + 5  学术水平 + 2  信用等级 + 2   查看全部评分

使用道具

板凳
小鳄鱼a 发表于 2015-5-6 14:00:22 |只看作者 |坛友微信交流群
learsaas 发表于 2015-5-6 12:41
给你个sql的比较傻的方法,好的方法我自己留着,呵呵。
proc sql noprint;
        create table table_n as
不好意思,id,code  可能都是很多的 ,对于每个id,要计算出code所有两两组合的重合率,然后除以这些组合数目球的对于每个id ,在某个时期的平均重合率

使用道具

报纸
小鳄鱼a 发表于 2015-5-7 21:47:33 |只看作者 |坛友微信交流群
在线等

使用道具

地板
yongyitian 发表于 2015-5-7 23:00:58 |只看作者 |坛友微信交流群
  1. /* this is partial code that count the number of repeated sd */
  2. /* you need to find the number of distinct sd in each time-id group
  3.    then calculate the wanted ratio */

  4. data have;
  5. input time id code  sd;
  6. datalines;
  7. 199806        1        1        1
  8. 199806        1        1        2
  9. 199806        1        1        4
  10. 199806        1        2        4
  11. 199806        1        2        2
  12. 199806        1        2        5
  13. 199806        1        3        1
  14. 199806        1        3        8
  15. 199806        2        1        5
  16. 199806        2        1        4
  17. 199806        2        1        7
  18. 199806        2        1        2
  19. 199806        2        2        5
  20. 199806        2        2        1
  21. 199806        2        3        4
  22. 199806        2        3        7
  23. 199806        2        3        1
  24. 199806        2        3        5
  25. 199812        1        3        8
  26. 199812        1        1        3
  27. 199812        1        1        7
  28. 199812        1        1        4
  29. 199812        1        1        5
  30. 199812        1        1        1
  31. 199812        1        2        7
  32. 199812        1        2        8
  33. 199812        1        2        9
  34. 199812        1        3        1
  35. 199812        1        3        5
  36. ; run;


  37. proc sql noprint;
  38.     select max(maxcode), max(maxsd) into: max_code,
  39.                                         : max_sd
  40.      from (select max(code) as maxcode, max(sd) as maxsd
  41.            from have
  42.            group by time, id);
  43. quit;
  44. %put &max_code;
  45. %put &max_sd;

  46. data want;
  47.    array code_sd{&max_code, &max_sd} _temporary_ ;
  48.    array c{&max_code} _temporary_ ;

  49.    do i = 1 to &max_code;
  50.      do j = 1 to &max_sd;
  51.        code_sd[i,j]=0;
  52.    end; end;

  53.    do until (last.id);
  54.      set have;
  55.      by time id;
  56.      code_sd[code, sd] = sd;
  57.    end;

  58.     do i = 1 to dim(c);
  59.      c[i]= 0; end;
  60.     do i = 1 to &max_code - 1;      
  61.      do j = i+1 to &max_code;
  62.       do k = 1 to &max_sd;
  63.        if code_sd[i,k]=code_sd[j,k] and code_sd[i,k] > 0 then c[i]+1;
  64.     end; end; end;

  65.     total_count = 0;
  66.     do i = 1 to dim(c);
  67.       total_count = total_count + c[i];  
  68.     end;
  69.     output; keep time id total_count;
  70. run;
复制代码
已有 1 人评分论坛币 热心指数 收起 理由
小鳄鱼a + 5 + 4 精彩帖子

总评分: 论坛币 + 5  热心指数 + 4   查看全部评分

使用道具

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

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

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

GMT+8, 2024-4-28 11:54