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. 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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