Thank you so much once again SuryaKiran, that was very helpful. I was able to get my data in shape with your recommendations of merging two datasets - I just had to tweak it slightly to fit my data. Thanks again for looking into my data issues - this is the code I ended up using. proc sort data=have
by patid month;
run;
data want (keep=patID exposure month phosphorus calcium_corrected recent_phosphorus recent_CA_corrected outcome Outcome_);
Merge have have (firstobs=2 keep=outcome USRDS_ID rename=(outcome=Outcome_ patID=patID2));
lag_ph=lag(phosphorus);
lag_cal=lag(calcium_corrected);
if month=0 then do;
phosphorus=recent_phosphorus;
calcium=recent_CA_corrected;
outcome=Outcome_;
end;
else do;
phosphorus=lag_ph;
calcium_corrected=lag_cal;
outcome=Outcome_;
if patID ne patID2 then outcome=.;
end;
run;
... View more