First off, this may not be what you want. Each record will have 3 DOC + 3 DOS + 3 PAID variables.
Use the RETAIN, and FIRST./LAST. functions of SAS
proc sort data=hw2; by ID DOC; run;
data oneID(drop=numrecs);
retain numrecs DOC1 DOC2 DOC3 DOS1 DOS2 DOS3 paid1 paid2 paid3;
set hw2;
by ID;
if first.ID then do;
numrecs=1; DOC1=DOC; DOS1=DOS; paid1=paid;
DOC2=" "; DOC3=" "; DOS2=" "; DOS3=" "; paid2=.; paid3=.;
end;
else numrecs=numrecs+1;
if numrecs=2 then do;
DOC2=DOC; DOS2=DOS; paid2=paid;
end;
else if numrecs=3 then do;
DOC3=DOC; DOS3=DOS; paid3=paid;
end;
else put "Error: More than 3 records for : " ID= numrecs= ;
if last.ID then output;
run;
That's it. However, if DOC will only be either A or D or Z then you could make a little change that might be better:
proc sort data=hw2; by ID DOC; run;
data oneID;
retain DOS_A DOS_D DOS_Z paid_A paid_D paid_Z;
set hw2;
by ID;
if first.ID then do;
DOS_A=" "; DOS_D=" "; DOS_Z=" "; paid_A=.; paid_D=.; paid_Z=.;
end;
if DOC="A" then do;
DOS_A=DOS; paid_A=paid;
end;
else if DOC="D" then do;
DOS_D=DOS; paid_D=paid;
end;
else if DOC="Z" then do;
DOS_Z=DOS; paid_Z=paid;
end;
else put "Error: DOC not in A/D/Z: " ID= DOC= ;
if last.ID then output;
run;





Reply With Quote


