BookmarkSubscribeRSS Feed
TheAzerty
Calcite | Level 5

Hello all,

 

I have 10 datasets going from input1 to input10. Then I want to transform them to iml data so I can do complex matrix calculations. The problem is that I can loop over the datasets with &i. as the variable suffix part. But I do not know how to loop over them when they are iml data, is it possible to do this in iml or is it just not possible?

 

proc iml;

%MACRO DO_BRANCH;

%do i=1 %to 10;

use input&i.;

read all var _ALL_ into imlData&i.[colname=varNames];

close input&i.;

%end;

%end;

%MEND DO_BRANCH;

%DO_BRANCH;

 

%The code below does not work !!

do i =1 to 10;

imlData&i.[1,1] = assign a new complex value (not important);

end;

 

If anybody knows the answer please tell me :), thank you all!

2 REPLIES 2
IanWakeling
Barite | Level 11

Have a look at CALL EXECUTE as you can use this to run IML statements that you have created in a character variable.  For example:

 

do i = 1 to 10;
  call execute( 'imlData' + strip(char(i)) + '[1,1] = 2#i;' );
end;

This should do what you want, but the problem is that a real program with a lot of CALL EXECUTEs can be difficult to read and to maintain, so you might be better off keeping all your data in one large matrix and then access individual matrices by subsetting rows and columns.

 

 

Note that you must use CALL EXECUTE inside an IML module.

Rick_SAS
SAS Super FREQ

The answer depends on what you want to do with the data.

1. Do you want to analyze each data set separately? (This is the most common wish.) Then you can read the data set names from an array like this:

proc iml;
dsName = "input1":"input10";
do i = 1 to ncol(dsName);
   use (dsName[i]);
   read all var _ALL_ into X;
   close (dsName[i]);
   /* do a computation for this data set */
end;

 

2. Do you want to read all of the data into IML matrices and then do computations across data sets? (This is rare.) If so, you can follow the directions in this article about reading data into separate matrices.

 

In either case, you don't need any macro code, so get rid of the %DO statements and replace them with SAS/IML DO loops.

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