ladyw 发表于 2010-4-21 22:29 
Obs famid year faminc
1 1 96 40000
2 1 97 40500
3 1 98 41000
4 2 96 45000
5 2 97 45400
6 2 98 45800
7 3 96 75000
8 3 97 76000
9 3 98 77000
data wide_array;
set long_sort;
by famid;
retain faminc96-faminc98;
array Afaminc(96:98) faminc96-faminc98;
if first.famid then do;
do i = 96 to 98;
Afaminc = .;
end;
end;
Afaminc(year) = faminc; /*looping across values in the variable year*/
if last.famid then output; /* outputs only the last obs in a family*/
drop year faminc i;
run;
proc print data=wide_array noobs;
run;
famid faminc96 faminc97 faminc98
1 40000 40500 41000
2 45000 45400 45800
3 75000 76000 77000
This is a good example to use the proc transpose rather than array in a data step.
The
proc transpose doesn't need any "maintenance" at all besides easiness to understand.
data tmp;
input famid year faminc ;
cards;
1 96 40000
1 97 40500
1 98 41000
2 96 45000
2 97 45400
2 98 45800
3 96 75000
3 97 76000
3 98 77000
;
proc transpose data=tmp out=tmp2(drop=_name_) prefix=faminc_;
by famid;
id year;
var faminc;
run;
proc print; run;