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

Hi everybody,

 

I hope this message finds you well.

I have a matrix, let's say MAT, and I would like to make the product of the elements on each row and output the resulting vector in VEC.

So VEC i = product MAT[ i , 1:NCOL(MAT)].

I simply figured it out using a do loop as follows:

     do i = 1 to nrow(MAT);
        do r = 1 to ncol(MAT);
          VEC [ i ,1]=VEC [i,1]*MAT[i,r];
       end;
    end;

 

But it takes too much time to run the above instructions since I have to run the same instructions 300,000 times (in different scenarios).

 

Do you have any better idea to optimize the runtime?

Thanks a lot in advance.

Raphaël

 

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ
vec = mat[ , #];

SAS/IML supports many elementwise operations. Two articles you might want to read are:

 

"Use subscript reduction operators"

and

"Compute statistics for each row by using subscript operators"

 

View solution in original post

4 REPLIES 4
Rick_SAS
SAS Super FREQ
vec = mat[ , #];

SAS/IML supports many elementwise operations. Two articles you might want to read are:

 

"Use subscript reduction operators"

and

"Compute statistics for each row by using subscript operators"

 

NewbieRaph
Calcite | Level 5

Thanks Rick! 🙂

It works perfectly and is 60 seconds faster for 20 scenarios.

You are my savior!

 I notice that you already posted it 3 years ago in your second link...

 

Raphael

 

 

Rick_SAS
SAS Super FREQ

Great. Remember to click the "Accept as Solution" button so that others can see that the question has been answered.

NewbieRaph
Calcite | Level 5

Done!!

 

Raphaël

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
  • 4 replies
  • 1097 views
  • 0 likes
  • 2 in conversation