I'm working with a nested loop using proc iml to replicate exisiting R code. I have a solution but it's computationally very slow. Below is the inner-most loop that I am wondering if I can vectorize for increased performance.
do k=1 to nrow(ru);
y={};
x=ru[k,];
submit x;
%ret(&x, data);
endsubmit;
This part of the code is looping through the elements of the ru vector and passing them as a macro variable into the ret function. The ret function produces datasets which end up producing subsequent ru vectors and the process is iterated many times. I'm pretty sure this is where the bottleneck in the code is coming from. Is it possible for me to pass the vector of ru elements without looping through each element?
Yes, you can pass a vector to the SUBMIT statement. You will get a space-separated list of values. You'll have to make your macro more complicated to handle this situation, but here's the idea:
proc iml;
ru = {3, 7, 10, 2};
/* old method */
do k=1 to nrow(ru);
x=ru[k,];
submit x;
%put &x;
endsubmit;
end;
/* new method */
submit ru;
%put &ru;
endsubmit;
Yes, you can pass a vector to the SUBMIT statement. You will get a space-separated list of values. You'll have to make your macro more complicated to handle this situation, but here's the idea:
proc iml;
ru = {3, 7, 10, 2};
/* old method */
do k=1 to nrow(ru);
x=ru[k,];
submit x;
%put &x;
endsubmit;
end;
/* new method */
submit ru;
%put &ru;
endsubmit;
You could this function to transform SAS matrix into R dataframe. and do loop in R statement.
proc iml; a = {1 2 3, 4 . 6}; call ExportMatrixToR(a, "m"); submit / R; print(m) endsubmit;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.