11-21-2016 03:17 PM
I have several stored matrices named like: DATA01 DATA02 DATA03 DATA04 DATA05... DATA20
I'd like to load and process them one at a time in a loop and I'd like to do this all in IML -- no macro code.
In pseudocode it would look like:
DO i = 1 TO 20; *** might have to do two loops, one for 01-09 and another for 10-20;
PRINT "SUM = " (DATA0i[+]); *** a simple calc;
I've got the matrix names stored in an array but I don't know how to evaluate the array elements in the loop so they resolve to DATA01, etc.
Any tips & suggestions are appreciated.
11-21-2016 04:53 PM
Are the matrices the same dimension? If so, the easiest way to process is to store them all in a data set and use an ID variable or a READ NEXT statement to process each matrix.
If you have to read 20 matrices that are stored, do yo uknow that there are 20 and that the matrix names are data1-data20?
11-21-2016 06:53 PM
The loading is easy because you can use
to read all matrices. Otherwise, explicitly name the matrices:.
load data1 data2;
The easiest way to process each matrix in a loop is to use the VALUE function to retrieve the matrix that is associated with each name. See the article "Indirect assignment: How to create and use matrices named x1, x2, ..., xn." Here is an example:
/* store some matrices */ proc iml; data1 = I(2); data2 = I(3); store data1 data2; quit; proc iml; load _all_; /* or load data1 data2; */ show names; do i = 1 to 2; matname = "data" + strip(char(i)); m = value(matname); PRINT "SUM = " (m[+]); *** a simple calc; end;