BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
dsriggs11
Fluorite | Level 6

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

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;

View solution in original post

2 REPLIES 2
Rick_SAS
SAS Super FREQ

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;
Ksharp
Super User

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 2 replies
  • 1328 views
  • 2 likes
  • 3 in conversation