It's possible to get there without using loops by making use of the EXPANDGRID function, and it can be generalized to any number of lists by constructing the required EXPANDGRID call in a string and then using CALL EXECUTE. Here is some code illustrating the smaller problem that you posted.
proc iml;
start knap;
/* make matrix of all the lists with missing value padding */
lists = {0 26 44 . . .,
0 52 65 78 . .,
0 4 12 20 27 46};
target = 116;
/* create binary matrix indicating where the list values are */
values = lists>.;
longlist = lists[loc(values)]; /* make one long list */
n = values[ , +];
/* work out where each individual list starts and end in longlist */
m = (1 + cusum(n) - n) || cusum(n);
s = rowcat( t( cats( char(m[,1]), ':', char(m[,2]), ',' )));
s = cats( 'e = expandgrid(', s, ');' );
print s; /* show the command s that is about to be executed */
call execute(s);
/* all possible combinations of values, one from each list */
c = shape( longlist[e], nrow(e), nrow(lists));
/* now use Rick's trick */
idx = loc(c[,+] = target);
if ncol(idx)>0
then print 'Target found :', (c[idx,]);
else print 'Target not found';
finish;
run knap;
quit;
... View more