Check my paper - Merge Skill:
http://support.sas.com/resources/papers/proceedings15/2785-2015.pdf
data have;
infile cards expandtabs truncover;
input ID (Date Diagnosis1 Diagnosis2 Diagnosis3 Diagnosis4 Diagnosis5) ($);
cards;
1 1/20/19 F123 F124
1 1/21/19 F284 F124 F3
1 1/22/19 F156
1 1/23/19 F189
2 2/1/19 F98
2 2/2/19 F78
3 3/1/19 F56
3 3/2/19 F57
3 3/3/19 F10 F11 F12 F13 F14
1 3/20/19 F17
3 9/1/19 F124
;
run;
proc transpose data=have out=temp(where=(col1 is not missing));
by id date notsorted;
var diag: ;
run;
data temp1;
set temp;
by id;
if first.id then n=0;
n+1;
run;
proc freq data=temp1 noprint;
table n/out=n list ;
run;
data _null_;
set n end=last;
if _n_=1 then call execute('data want;merge ');
call execute(catt('temp1(where=(n=',n,') rename=(date=date',n,' col1=diag',n,'))'));
if last then call execute(';by id;drop _name_ n ;run;');
run;
... View more