Very interesting article.
I tried to apply this on the code below but it doesn't work. In fact what I need to do is a litlle bit different I think. I have a population for which I know the age stored in a vector, and I want to get for each one the mortality rate from a mortality table.

For now, I have written this code, using loc function and apply function.
But when I use this code on large datasets, the code is quite slow because of apply function.

Is there a way to do it differently (and faster) using loc/element functions?

proc iml;

mortality_table=J(11,2);
/* age */
mortality_table[,1]={50,51,52,53,54,55,56,57,58,59,60};
/* mortality rate */
mortality_table[,2]={0.01,0.011,0.012,0.013,0.014,0.015,0.016,0.017,0.018,0.019,0.020};

/* age of the studied population */
population_age={50,50,53,53,60,60,51,51,54,54,54,51,52,52,52,57,52,55,57,59};

start mortality(x) global(mortality_table);
l=loc(mortality_table[,1]=x);
return(mortality_table[l,2]);
finish mortality;

/* mortality rates of the studied population */
population_mortality=apply("mortality",population_age);

print population_age population_mortality;

quit;