- 阅读权限
- 255
- 威望
- 0 级
- 论坛币
- 4511 个
- 通用积分
- 76.8946
- 学术水平
- 171 点
- 热心指数
- 204 点
- 信用等级
- 133 点
- 经验
- 24578 点
- 帖子
- 583
- 精华
- 1
- 在线时间
- 1865 小时
- 注册时间
- 2008-5-25
- 最后登录
- 2025-4-28
|
- data test;
- input id code date: yymmdd10. x y xvalue;
- format date yymmdd10.;
- cards;
- 1 1 1998-3-22 . 1 .
- 1 1 1999-5-6 1 . 4
- 1 1 1999-9-8 1 . 5
- 1 1 1999-10-21 1 . 6
- 1 1 2001-9-8 . 1 .
- 1 2 1996-5-1 1 . 8
- 1 2 1997-5-1 . 1 .
- 1 2 1997-9-6 1 . 10
- 1 2 1998-3-2 1 . 11
- 1 2 1998-4-26 1 . 12
- 1 2 1998-9-19 . 1 .
- 1 2 1998-10-26 . 1 .
- 1 2 1998-11-3 1 . .
- 1 2 1998-12-9 . 1 .
- ;
- run;
- data test1;
- set test;
- tag+1;
- retain uni1 0;
- retain uni2 0;
- 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;
- ydummy=1;
- uni1=id;
- uni2=code;
- end;
- if missing(lag(x)) then do;
- tag=0;
- end;
- run;
- proc sql noprint;
- select max(tag) into: maxtag from test1;
- quit;
- %macro temp;
- data test2;
- set test1;
- if &maxtag.>2 then do;
- temp1=lag(xvalue);
- date1=lag(date);
- %do i=2 %to &maxtag.;
- temp&i.=lag(temp%left(%eval(&i-1)));
- date&i.=lag(date%left(%eval(&i-1)));
- %end;
- end;
- if &maxtag.=2 then do;
- temp1=lag(xvalue);
- temp2=lag(temp1);
- date1=lag(date);
- date2=lag(date1);
- end;
- run;
- data test3;
- set test2;
- array tempx temp1-temp%left(&maxtag.);
- xlianxusumvalue=.;
- xgudingsumvalue=.;
- if ydummy=1 then do;
- do i=1 to tag;
- xlianxusumvalue+tempx[i];
- end;
- xgudingsumvalue=temp1;
- if tag>=2 then do;
- %do i=2 %to &maxtag.;
- if date1-date%left(%eval(&i))<180 then
- xgudingsumvalue=xgudingsumvalue+temp%left(%eval(&i));
- %end;
- end;
- end;
- keep id code date x y xvalue ydummy xlianxusumvalue xgudingsumvalue;
- run;
- %mend;
- %temp;
复制代码
|
-
总评分: 论坛币 + 40
学术水平 + 2
热心指数 + 2
信用等级 + 2
查看全部评分
|