turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

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;

LOAD DATAi;

PRINT "SUM = " (DATA0i[+]); *** a simple calc;

END;

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to stevo642

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?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to stevo642

11-21-2016 06:53 PM

The loading is easy because you can use

load _all_;

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;
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Rick_SAS

11-22-2016 11:06 AM

VALUE() works great, thank you!