BookmarkSubscribeRSS Feed
Felipe_bortolo
Fluorite | Level 6

Hello friends,

 

I’m not that used with SAS IML syntax and I’m trying to do something that seems to be very simple: creating matrices dynamically into a Do Loop.

 

What I’m trying to do is using the iterator number as part of the matrix names (because I will create a bunch of matrices, as I said, dynamically) but I just can’t figure out how.

Here is a simple example of how it should be:

 

PROC IML;

DO X = 1 TO 10;
      MAT_&X. = J(10, 20, 1); /*or something like that…*/
END;
QUIT;

 

In other words, I just would like to concatenate “MAT_” with the iteration number to name the matrix, but I’m failing miserably…

 

Can anyone help me with this issue, please?

 

Note: I'm using the IML languague into SAS Guide scripts.

2 REPLIES 2
Ksharp
Super User
PROC IML;

M="MAT_1":"MAT_10"; 
DO X = 1 TO ncol(M);
 call valset(M[X],J(2,rand('integer',1,4), 1));
 print (value(M[X]));
END;

QUIT;
Rick_SAS
SAS Super FREQ

Can you say more about what you intend to do with these matrices?

 

I have seen a few cases where the programmer thinks he needs to do. But in most cases, the program only requires one matrix at a time. If that i the case for your application, create the matrix, M, inside the loop, use it, and then use the same name for the next iteration. 

 

I've also seen applications where the program requires M_new and M_old. If that is the case, set M_old=M_new at the bottom of the DO loop, and reassign M_new at the top of the loop. 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 341 views
  • 0 likes
  • 3 in conversation