My approach would have been different from a macro approach. I stuck with DATA step for the solution, assuming the data was stored in a file called PTINFO, with the variables VAR1 (patient id) and VAR2:
[pre]
proc sort data=ptinfo out=ptinfo;
by var1;
run;
data newpt(keep=var1 newvar2);
set ptinfo; by var1;
length newvar2 $200 sep $2;
retain sep ', ' newvar2;
if first.var1 then newvar2 = ' ';
newvar2 = catx(sep,newvar2,var2);
if last.var1 then output;
run;
proc print data=newpt;
title 'New PT file';
run;
[/pre]
Yields this result from the proc print:
[pre]
New PT file
Obs var1 newvar2
1 a101 aaaa, bbbb
2 a102 cccc
3 a103 dddd, eeee, fffff
[/pre]
The ability to use BY group processing and FIRST.VAR1 and LAST.VAR1 made it possible to read through every PT observation and build a new variable called NEWVAR2 by concatenating the single value for VAR2 onto the value of NEWVAR2 for every row. The only other things needed to make this work are the reinitialization of NEWVAR1 for the first record for a patient and then to control the output using an explicit OUTPUT statement on the last record for a patient.
cynthia