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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Multiple Linear Regression in SAS

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.

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