楼主: 小鳄鱼a
1342 1

问题求助 [推广有奖]

  • 6关注
  • 10粉丝

已卖:280份资源

学科带头人

3%

还不是VIP/贵宾

-

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

楼主
小鳄鱼a 发表于 2016-6-14 23:14:23 |AI写论文
500论坛币
请看看示例文件,写的还算清楚,不清楚的请留言
关键词:示例文件

沙发
l1i2n3i4n5g 在职认证  发表于 2016-6-14 23:14:24
  1. data test;
  2. input id code date: yymmdd10.        x y xvalue;
  3. format date yymmdd10.;
  4. cards;
  5. 1        1        1998-3-22        .        1        .
  6. 1        1        1999-5-6        1        .        4
  7. 1        1        1999-9-8        1        .        5
  8. 1        1        1999-10-21        1        .        6
  9. 1        1        2001-9-8        .        1        .
  10. 1        2        1996-5-1        1        .        8
  11. 1        2        1997-5-1        .        1        .
  12. 1        2        1997-9-6        1        .        10
  13. 1        2        1998-3-2        1        .        11
  14. 1        2        1998-4-26        1        .        12
  15. 1        2        1998-9-19        .        1        .
  16. 1        2        1998-10-26        .        1        .
  17. 1        2        1998-11-3        1        .        .
  18. 1        2        1998-12-9        .        1        .
  19. ;
  20. run;

  21. data test1;
  22. set test;
  23. tag+1;
  24. retain uni1 0;
  25. retain uni2 0;
  26. if (id^=uni1 or code^=uni2) and id=lag(id) and code=lag(code) and y=1 and lag(x)=1 and  date-lag(date)<180 then do;
  27. ydummy=1;
  28. uni1=id;
  29. uni2=code;
  30. end;
  31. if missing(lag(x)) then do;
  32. tag=0;
  33. end;
  34. run;

  35. proc sql noprint;
  36.   select max(tag) into: maxtag from test1;
  37. quit;

  38. %macro temp;
  39. data test2;
  40. set test1;
  41.         if &maxtag.>2 then do;
  42.                 temp1=lag(xvalue);
  43.                 date1=lag(date);
  44.                 %do i=2 %to &maxtag.;
  45.                 temp&i.=lag(temp%left(%eval(&i-1)));
  46.                 date&i.=lag(date%left(%eval(&i-1)));
  47.                 %end;
  48.         end;
  49.         if &maxtag.=2 then do;
  50.                 temp1=lag(xvalue);
  51.                 temp2=lag(temp1);
  52.                 date1=lag(date);
  53.                 date2=lag(date1);
  54.         end;
  55. run;

  56. data test3;
  57. set test2;
  58. array tempx temp1-temp%left(&maxtag.);
  59. xlianxusumvalue=.;
  60. xgudingsumvalue=.;
  61. if ydummy=1 then do;
  62.         do i=1 to tag;
  63.                 xlianxusumvalue+tempx[i];
  64.         end;
  65.         xgudingsumvalue=temp1;
  66.         if tag>=2 then do;
  67.         %do i=2 %to &maxtag.;
  68.                 if date1-date%left(%eval(&i))<180 then
  69.                 xgudingsumvalue=xgudingsumvalue+temp%left(%eval(&i));
  70.         %end;
  71.         end;
  72. end;
  73. keep id code date x y xvalue ydummy xlianxusumvalue xgudingsumvalue;
  74. run;
  75. %mend;
  76. %temp;
复制代码

已有 1 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
admin_kefu + 40 + 2 + 2 + 2 精彩帖子

总评分: 论坛币 + 40  学术水平 + 2  热心指数 + 2  信用等级 + 2   查看全部评分

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-2-17 15:36