|
Technical Report #5: Collapsing Multiple Observations For An Individual Into A Single Observation Bruce Ratner, Ph.D. Objective: Reshape data by collapsing multiple records for an individual into a single record. Solution: data orders; input id y z $; cards; 1 1 b 1 7 r 1 9 g 1 14 u 2 1 c 3 2 e ; run; proc print;run; proc sort;by id;run; data orders_spread (keep=id y1-y5 z1-z5); retain y1-y5 z1-z5; array y_ (*) y1-y5; array z_ (*) $ z1-z5; set orders; by id; if first.id then do; i=1; do j= 1 to 5; y_(j)= . ; z_(j)= ' ' ; end; end; y_(i)=y; z_(i)=z; if last.id then output; i+1; run; proc print data=orders_spread;run; 1 800 DM STAT-1, or e-mail at br@dmstat1.com. |
|