<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to loop over a list of stored matrices to sequentially load and process them in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-loop-over-a-list-of-stored-matrices-to-sequentially-load/m-p/313235#M3089</link>
    <description>&lt;P&gt;I have several stored matrices named like: DATA01&amp;nbsp; DATA02&amp;nbsp; DATA03&amp;nbsp; DATA04&amp;nbsp; DATA05... DATA20&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In pseudocode it would look like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;DO i = 1 TO 20;&amp;nbsp; &lt;/FONT&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; *** might have to do two loops, one for 01-09 and another for 10-20;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; LOAD DATAi;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; PRINT "SUM = " (DATA0i[+]);&amp;nbsp; *** a simple calc;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;END;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any tips &amp;amp; suggestions are appreciated.&lt;/P&gt;</description>
    <pubDate>Mon, 21 Nov 2016 20:17:40 GMT</pubDate>
    <dc:creator>stevo642</dc:creator>
    <dc:date>2016-11-21T20:17:40Z</dc:date>
    <item>
      <title>How to loop over a list of stored matrices to sequentially load and process them</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-loop-over-a-list-of-stored-matrices-to-sequentially-load/m-p/313235#M3089</link>
      <description>&lt;P&gt;I have several stored matrices named like: DATA01&amp;nbsp; DATA02&amp;nbsp; DATA03&amp;nbsp; DATA04&amp;nbsp; DATA05... DATA20&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In pseudocode it would look like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;DO i = 1 TO 20;&amp;nbsp; &lt;/FONT&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; *** might have to do two loops, one for 01-09 and another for 10-20;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; LOAD DATAi;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; PRINT "SUM = " (DATA0i[+]);&amp;nbsp; *** a simple calc;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;END;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any tips &amp;amp; suggestions are appreciated.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2016 20:17:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-loop-over-a-list-of-stored-matrices-to-sequentially-load/m-p/313235#M3089</guid>
      <dc:creator>stevo642</dc:creator>
      <dc:date>2016-11-21T20:17:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to loop over a list of stored matrices to sequentially load and process them</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-loop-over-a-list-of-stored-matrices-to-sequentially-load/m-p/313290#M3093</link>
      <description>&lt;P&gt;Are the matrices the same dimension? &amp;nbsp; 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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have to read&amp;nbsp;20 matrices that are stored, do yo uknow that there are 20 and that the matrix names are data1-data20?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2016 21:53:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-loop-over-a-list-of-stored-matrices-to-sequentially-load/m-p/313290#M3093</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-11-21T21:53:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to loop over a list of stored matrices to sequentially load and process them</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-loop-over-a-list-of-stored-matrices-to-sequentially-load/m-p/313307#M3094</link>
      <description>&lt;P&gt;The loading is easy because you can use&amp;nbsp;&lt;/P&gt;
&lt;P&gt;load _all_;&lt;/P&gt;
&lt;P&gt;to read all matrices. Otherwise, explicitly name the matrices:.&lt;/P&gt;
&lt;P&gt;load data1 data2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The easiest way to process&amp;nbsp;each matrix in a loop is to use the VALUE function to retrieve the matrix that is associated with each name. See the article &lt;A href="http://blogs.sas.com/content/iml/2011/03/23/indirect-assignment-how-to-create-and-use-matrices-named-x1-x2-xn.html" target="_self"&gt;"Indirect assignment: How to create and use matrices named x1, x2, ..., xn."&lt;/A&gt;&amp;nbsp; Here is an example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* 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;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2016 23:53:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-loop-over-a-list-of-stored-matrices-to-sequentially-load/m-p/313307#M3094</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-11-21T23:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to loop over a list of stored matrices to sequentially load and process them</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-loop-over-a-list-of-stored-matrices-to-sequentially-load/m-p/313509#M3097</link>
      <description>VALUE() works great, thank you!</description>
      <pubDate>Tue, 22 Nov 2016 16:06:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-loop-over-a-list-of-stored-matrices-to-sequentially-load/m-p/313509#M3097</guid>
      <dc:creator>stevo642</dc:creator>
      <dc:date>2016-11-22T16:06:18Z</dc:date>
    </item>
  </channel>
</rss>

