Data defines the model by dint of genetic programming, producing the best decile table.


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 or 1 800 DM STAT-1; or e-mail at br@dmstat1.com.
Sign-up for a free GenIQ webcast: Click here.