BookmarkSubscribeRSS Feed
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;


%do i=1 %to 10;

use input&i.;

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

close input&i.;






%The code below does not work !!

do i =1 to 10;

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



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

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;' );

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.


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 */


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.



Time is running out to save with the early bird rate. Register by Friday, March 1 for just $695 - $100 off the standard rate.


Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 


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
  • 3 in conversation