BookmarkSubscribeRSS Feed
MarkGIP
Calcite | Level 5

Hi! It's me again....

While working with the DO loop function I encountered another problem;) I'd like to create several matrices with the help of the DO loop function but I'm still struggling with the matrices' names. Is it possible to assign a matrix name via the DO loop function as well?

Example:

do i=1 to 10;

Matrix_i=.....

end;

Thank you for your help!

2 REPLIES 2
MarkGIP
Calcite | Level 5

Oh... nevermind. I just discovered the article of Rick on this topic..... Thank you Rick;)

But maybe somebody knows how to address a specific matrix with the DO Loop Function.

Example:

the functions are as follows:

m1=x1

m2=x2-x1

...

m10=x10-x9

Thank you....

Rick_SAS
SAS Super FREQ

It is very rare that you need to have matrices of different names (as I explain in the article prior to the one you reference).

Sometimes people THINK they need to do this because they are trying to wrap SAS/IML statements within a macro loop, which is rarely necessary. Instead, you can use the SAS/IML language itself  to perform whatever the macro loop is doing.

You didn't post an example, but one common programming technique is to have all of the x vars in an nx10 matrix, where each column is a variable.

Then the following statements form a matrix m where each column is what you want:

y = j(n,1,0) || x; /* temp: append column of zeros */

m = y[,2:11] - y[,1:10];

free y;

Another alternative, if you don't need the whole matrix, is to loop:

do i = 1 to 10;

   if i = 1 then m=x[,i];

   else m = x[,i] - x[,i-1];

   /* do something with m, which is m_i in your notation */

end;

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
  • 899 views
  • 0 likes
  • 2 in conversation