类似于:
data tem;
input id code$ date yymmdd10.;
format date yymmdd10.;
cards;
1 A 2003-04-16
1 B 2003-04-29
2 A 2003-05-12
2 B 2003-06-01
2 C 2003-06-12
;run;
proc sort data=tem;by id descending date;run;
data tem;
set tem;
format lag_date yymmdd10.;
by id;
lag_date=lag(date);
if code='A' and lag(code)='B' then duration=lag_date-date;
drop lag_date;
run;