OK. I did not take into account of this scenario .
Try this one :
data have;
input State $ city $ (Stdt endt)(:mmddyy10.) Treatment $;
format Stdt endt mmddyy10.;
datalines;
NY NeyYork 01/01/2010 03/01/2010 Dialysis
NY NeyYork 01/01/2011 03/01/2011 Dialysis
MD Baltimore 01/01/2011 08/01/2011 Dialysis
MD Baltimore 02/01/2011 12/01/2011 Heart
MD Baltimore 03/02/2011 02/14/2015 Urine
MD Baltimore 04/15/2011 01/14/2015 Dialysis
MD Baltimore 02/01/2011 05/01/2011 Knee
;
run;
data temp;
set have;
do date=Stdt to endt;
output;
end;
format date mmddyy10.;
drop Stdt endt;
run;
proc sort data=temp nodupkey;by State city date Treatment;run;
data temp2;
do until(last.date);
set temp;
by State city date;
length Treatments $ 100;
Treatments=catx('/',Treatments,Treatment);
end;
drop Treatment;
run;
data temp3;
set temp2;
by State city Treatments notsorted;
if first.Treatments or dif(date) ne 1 then group+1;
run;
data want;
set temp3;
by group;
retain Stdt ;
if first.group then Stdt=date;
if last.group then do;endt=date;output;end;
format Stdt endt mmddyy10.;
drop date;
run;
... View more