- data indsn;
- input NO $ Code $ Code_Date $;
- datalines;
- 100023 TS1 2012/4/19
- 100023 TS2 2012/4/23
- 100028 TS1 2012/4/25
- 100028 TS2 2012/4/27
- 100055 TS1 2012/5/2
- 100055 TS2 2012/5/4
- 100059 TS1 2012/5/7
- 100059 TS2 2012/5/8
- 100059 TS2 2012/5/9
- 100073 TS1 2012/5/2
- 100073 TS2 2012/5/4
- ;
- proc sql;
- create table outdsn as
- select a.*,
- case when a.code='TS1' then .
- when a.Code_Date ^='' and b.Code_Date ^='' then input(a.Code_Date,yymmdd10.)- input(b.Code_Date,yymmdd10.)
- end as dur
- from indsn a left join indsn(where=(code='TS1')) b on a.no=b.no
- order by no, code, code_date;
- quit;