- 阅读权限
- 255
- 威望
- 0 级
- 论坛币
- 14 个
- 通用积分
- 0.4174
- 学术水平
- 20 点
- 热心指数
- 26 点
- 信用等级
- 12 点
- 经验
- 17989 点
- 帖子
- 478
- 精华
- 0
- 在线时间
- 1627 小时
- 注册时间
- 2011-2-24
- 最后登录
- 2025-8-3
|
|
- try this
- data a;
- input company date:yymmn6. id;
- format date yymmn6.;
- datalines;
- 1001 200509 2
- 1001 200510 6
- 1001 200511 2
- 1001 200512 6
- 1119 200112 .
- 1119 200201 .
- 1119 200202 6
- 1119 200203 8
- ;
- run;
- /*code 1*/
- data bb;
- temp=0;
- ccc=0;
- do _n_=1 by 1 until(last.company);
- set a;
- by company;
- temp=ifn(^missing(id),temp+1,temp);
- ccc=ifn(^missing(id) and temp=1,id,ccc);
- put temp ccc;
- end;
- do _n_=1 to _n_;
- set a;
- if ^missing(id) then id=ccc;
- output;
- end;
- run;
- /*code 2*/
- data aa;
- input company date:yymmn6. id;
- format date yymmn6.;
- datalines;
- 1001 200509 2
- 1001 200510 6
- 1001 200511 .
- 1001 200512 6
- 1119 200112 .
- 1119 200201 .
- 1119 200202 6
- 1119 200203 8
- ;
- run;
- data bbb;
- temp=0;
- ccc=0;
- ddd=0;
- do _n_=1 by 1 until(last.company);
- set a;
- by company;
- temp=ifn(^missing(id),temp+1,temp);
- ccc=ifn(^missing(id) and temp=1,id,ccc);
- ddd=ifn(^missing(id) and temp=1,_n_,ddd);
- put temp ccc ddd;
- end;
- do _n_=1 to _n_;
- set a;
- if ddd eq 1 then do;
- id=ccc;
- output;
- end;
- else do;
- if _n_ ge ddd then id=ccc;
- else call missing(id);
- output;
- end;
- end;
- run;
复制代码
|
|