Hi @NLIL,
I agree with @PaigeMiller, it would be easier if you could share a portion of your data to better understand what problem you're trying to solve.
I have some doubt about you approach to select the oldest diagnosis in case you have more than one record for an ID -> with a "descending" proc sort, if think you're doing the opposite.
Here is maybe something you can try, but I am not pretty sure this is what you want.
/* if same ID and diagnose, keep the oldest one */
proc sort data=mydata;
by ID_ Diag1 Diag2 Diag3 DateIn;
run;
data mydata2;
set mydata;
by ID_ Diag1 Diag2 Diag3;
if first.diag3;
run;
/* transform dataset as a long one instead of wide, regarding the diagnoses */
proc transpose data=mydata2 out=mydata_tr (drop=_name_);
var MainDiag Diag1 Diag2 Diag3;
id id_;
by notsorted DateIn ;
run;
... View more