Something like this, maybe?
data a;
infile datalines dsd;
INPUT PatID Days Treatment;
label patid='Patient ID' Days= 'Days from diagnosis' ;
datalines;
1,0,0
1,100,1
1,150,1
1,200,1
1,250,0
;
title "A";
proc print; run;
data b;
infile datalines dsd;
INPUT PatID Days Hospitalized;
label patid='Patient ID' Days= 'Days from diagnosis' ;
datalines;
1,0,0
1,100,0
1,180,1
1,220,1
;
title "B";
proc print; run;
data C;
merge a b;
by PatID days;
/* If new Hospitalized between Treatment dates, use previous treatment */
Treatment=coalesce(Treatment,lag1(Treatment));
/* If new Treatment between Hospitalized dates, use 0 */
Hospitalized=coalesce(Hospitalized,0);
run;
title "C";
proc print; run;
... View more