DM Stat-1 Articles
Link to Home

Link to Articles

Link to Consulting

Link to Seminar

Link to Stat-Chat

Link to Software

Link to Clients

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;



For more information about this article, call Bruce Ratner at 516.791.3544,
1 800 DM STAT-1, or e-mail at br@dmstat1.com.