Date: Mon, 18 Feb 2008 15:09:39 -0500
Reply-To: Jerry <greenmt@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jerry <greenmt@GMAIL.COM>
Subject: a better alternative to collapse data?
Hi,
I have a data set "dsin" look like below,
/**********/
data dsin;
length idindex 3 code $3;
input idindex code $;
datalines;
1 256
1 287
1 985
2 660
2 966
3 811
3 809
3 178
3 271
4 352
4 210
;
run;
To collapse the data above by "idindex" to the desired layout below:
idindex cd_1 cd_2 cd_3 cd_4
1 256 287 985
2 660 966
3 811 809 178 271
4 352 210
I have the code below to do so
/****/
proc sort data=dsin;
by idindex;
run;
data dsout (drop=cdcnt code);
/*because for each distinctive value of variable "idindex", there are at
most four codes.*/
array cd {*} $3 cd1-cd4;
do until(last.idindex);
set dsin; by idindex;
if first.idindex then cdcnt=0;
cdcnt+1;
cd{cdcnt}=code;
end;
run;
/****/
I wonder if anyone can help me find a better alternative to my approach in
terms of efficacy (i.e. minimizing running time).
Any input is greatly appreciated.
Jerry