data have;
input patid fill_dt : mmddyy10. days_sup;
format fill_dt mmddyy10.;
datalines;
1 10/21/2015 20
1 11/10/2015 20
1 11/30/2015 30
2 5/1/2013 20
2 5/20/2013 10
2 6/10/2013 3
;
run;
data temp;
set have;
by patid;
retain k;
if first.patid then do; grp=0;k=0;end;
if not(fill_dt <= k) then grp+1;
k=intnx('days',fill_dt,days_sup);
drop k;
run;
proc sql;
create table want as
select patid ,fill_dt,sum(days_sup) as sum
from temp
group by patid, grp
having fill_dt=min(fill_dt)
order by patid, fill_dt;
quit;
... View more