Tom, Thank you for your solution. I ended up using this code. I have also attached the log. i was able to get the output I desired. I just wanted someone to look at the log for correctness before I apply this to the actual dataset. data want ;
merge have (where = (labtest='Calcium') rename = (result=calcium date=calcium_date event=calcium_event))
have (where = (labtest='Pot') rename = (result=potassium date=pot_date event=pot_event))
have (where = (labtest='Mag') rename = (result=Magnesium date=Mag_date event=Mag_event))
have (where = (labtest='Creat') rename = (result=Creatnine date=Creat_date event=Creat_event))
;
by id;
output;
call missing(of _all_);
drop labtest;
run; SAS LOG 103 data want ; 104 merge have (where = (labtest='Calcium') rename = (result=calcium date=calcium_date 104! event=calcium_event)) 105 have (where = (labtest='Pot') rename = (result=potassium date=pot_date 105! event=pot_event)) 106 have (where = (labtest='Mag') rename = (result=Magnesium date=Mag_date 106! event=Mag_event)) 107 have (where = (labtest='Creat') rename = (result=Creatnine date=Creat_date 107! event=Creat_event)) 108 ; 109 by id; 110 output; 111 call missing(of _all_); 112 drop labtest; 113 run; NOTE: MERGE statement has more than one data set with repeats of BY values. NOTE: There were 3 observations read from the data set WORK.HAVE. WHERE labtest='Calcium'; NOTE: There were 6 observations read from the data set WORK.HAVE. WHERE labtest='Pot'; NOTE: There were 6 observations read from the data set WORK.HAVE. WHERE labtest='Mag'; NOTE: There were 3 observations read from the data set WORK.HAVE. WHERE labtest='Creat'; NOTE: The data set WORK.WANT has 6 observations and 13 variables. NOTE: DATA statement used (Total process time): real time 0.02 seconds cpu time 0.01 seconds @Tom wrote: Looks like you are just pasting the values for CALCIUM next to the values for POT, MAG, etc.. You can do that with the MERGE statement, if you take care to clear the values before the next interation of the data step. data want ;
merge have (where = (labtest='Calcium') rename=result=calcium_result date=calcium_date .... )
have (where = (labtest='Pot') rename=result=pot_result date=pot_date .... )
;
by id;
output;
call missing(of _all_);
run;
... View more