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?
%do i=1 %to 10;
read all var _ALL_ into imlData&i.[colname=varNames];
%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!
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.
dsName = "input1":"input10";
do i = 1 to ncol(dsName);
read all var _ALL_ into X;
/* 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.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.