@mirib
You would have received my reply now.
After posting it, I realized that the code is not generalized. It will work if you arrange the columns as
array f f&start_col - f&end_col;
where &start_col has to be always 2 and &end_col has to be 6. What if you want:
input age f4 - f8;
instead of
input age f2 f3 f4 f5 f6;
A small correction to the previous code is made which takes care of any starting and ending column names ( they have to be contiguous in between):
data have;
infile cards expandtabs truncover;
input age f4 - f8;
cards;
40 11 15 5 9 14
41 15 8 51 56 12
42 25 7 5 10 5
43 3 16 66 71 32
44 55 181 23 28 12
45 1 184 12 17 1
;
run;
%let start_row = 40;
%let end_row = 45;
%let start_col = 4;
%let end_col = 8;
data _null_;
/** Load the 2-dimensional Array **/
if _n_ = 1 then do until(eof);
set have end = eof;
array ind[&start_row:&end_row, &start_col:&end_col] _temporary_;
array f[&start_col:&end_col] f&start_col - f&end_col;
row = age;
do i = &start_col to &end_col;
col = input(compress(vname(f[i]),,'kd'),8.);
ind[row,col] = f[i];
*put row = col = ind[row, col] =;
end;
end;
/** Lookup the Array **/
do age = 42, 40;
do i = 5, 4, 6;
put ind[age, i] =;
end;
put '==================================';
end;
stop;
run;
... View more