I need to look-up the values from matrix 'a' in the first column of matrix 'b' and return the values in the second column of matrix 'b' to a new matrix named 'c'. The rows in matrix 'b' are a key-value pairs, basically. This code achieves that, but I would like to know whether there is a vectorized aproach to this instead of a do loop. proc iml;
a = {100 202 303,
107 200 303,
101 205 302,
102 200 300};
b = {100 1,
101 8,
102 1,
104 6,
107 4,
108 9,
200 4,
202 6,
205 2,
300 10,
301 5,
302 2,
303 8,
304 10};
/*the Do LOOP way*/
c = j(4,3,.);
do i = 1 to 4;
do j = 1 to 3;
idx = loc(b[,1] = a[i,j]);
c[i,j] = b[idx,2];
end;
end;
print c;
quit; The expected output in matrix 'c': c
1 6 8
4 4 8
8 2 2
1 4 10
... View more