02-29-2016 04:45 AM - edited 02-29-2016 04:46 AM
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!
02-29-2016 05:41 AM
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.
02-29-2016 07:43 AM - edited 02-29-2016 07:43 AM
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.