Hi, I'm writing a program that stores lookup data in a multi-dimensional array and I need to return the row index of the array to eliminate hard coding of values. The sas functions whichc and whichn are designed for this but they return the position of the lookup value expressed as a list. data want;
array foo [3,5] $2 _temporary_
(
'a1' 'b1' 'c1' 'd1'
'a2' 'b2' 'c2' 'd2'
'a3' 'b3' 'c3' 'd3'
); drop i;
do i = 1 to dim(foo);
key = foo[i,1];
does_lkup_as_1_dimension = whichc(key,of foo[*]);
real_index = int(whichc(key,of foo[*])/dim2(foo))+1;
output;
end;
run; The above code returns the following values for a lookup on a 3 * 4 dimension array in the variable 'does_lkup_as_1_dimension'. key does_lkup_as_1_dimension real_index a1 1 1 a2 6 2 a3 11 3 I am using this as a workaround which returns the value I want. real_index = int(whichc(key,of foo[*])/dim2(foo))+1; Is there a better way with native SAS functions? I'm surprised I have not needed to do this until now and I expect I'm not the first! Thanks in advance. Cam
... View more