More data would be better.
Check the MERGE skill proposed by Me,Matt,Arthur.T
http://support.sas.com/resources/papers/proceedings15/2785-2015.pdf
data have;
input PatientID Drugname : $20. recieveddate : $20. strength;
cards;
1 Cefrriaxone 1/1/2016 500
1 Cefrriaxone 2/1/2016 500
2 Cefaclor 5/6/2016 1000
2 Cefaclor 6/6/2016 1000
;
run;
data temp(index=(xx=(PatientID strength)));
set have;
by PatientID Drugname strength;
if first.strength then n=0;
n+1;
run;
proc sql;
select distinct catt('temp(where=(n=',n,'and PatientID=',PatientID,'and strength=',strength,')
rename=(recieveddate=',cats(Drugname,'Date',n),'))')
into : merge separated by ' '
from temp;
quit;
data want;
merge &merge;
by PatientID strength;
output;
call missing(of _all_);
drop Drugname n;
run;
... View more