<?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 Using Loop Index in Name in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Using-Loop-Index-in-Name/m-p/443045#M4050</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Suppose I have the following code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
	class_1 ={1 0 2,
		  2 3 2};
	class_2 ={4 2 3,
		  2 6 2};
	div ={1	2 4,
 	      6	8 10};
	new_1 = class_1 / div;
	new_2 = class_2 / div;
	print new_1;
	print new_2;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want to set up a loop to reduce the code. So something like&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	do i = 1 to 2;
		new_i = class_i / div;
		print new_i;
		end;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What's the proper way to extract the value of i and use it as an actual value?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 06 Mar 2018 21:05:12 GMT</pubDate>
    <dc:creator>jl1005</dc:creator>
    <dc:date>2018-03-06T21:05:12Z</dc:date>
    <item>
      <title>Using Loop Index in Name</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Using-Loop-Index-in-Name/m-p/443045#M4050</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Suppose I have the following code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
	class_1 ={1 0 2,
		  2 3 2};
	class_2 ={4 2 3,
		  2 6 2};
	div ={1	2 4,
 	      6	8 10};
	new_1 = class_1 / div;
	new_2 = class_2 / div;
	print new_1;
	print new_2;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want to set up a loop to reduce the code. So something like&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	do i = 1 to 2;
		new_i = class_i / div;
		print new_i;
		end;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What's the proper way to extract the value of i and use it as an actual value?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Mar 2018 21:05:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Using-Loop-Index-in-Name/m-p/443045#M4050</guid>
      <dc:creator>jl1005</dc:creator>
      <dc:date>2018-03-06T21:05:12Z</dc:date>
    </item>
    <item>
      <title>Re: Using Loop Index in Name</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Using-Loop-Index-in-Name/m-p/443061#M4051</link>
      <description>&lt;P&gt;For your example in which all variables are the same size, I recommend &lt;A href="https://blogs.sas.com/content/iml/2015/02/09/array-of-matrices.html" target="_self"&gt;"flattening" the data into row vectors and storing the matrices as rows in a matrix.&amp;nbsp;&lt;/A&gt;&amp;nbsp;For your example, it would look like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;nr = 2;  /* number of rows */
nc = 3;  /* number of cols */
nMatrices = 2;  /* total number of matrices being stored */

class = {
1 0 2  2 3 2,  /* first 2x3 matrix */
4 2 3  2 6 2}; /* second 2x3 matrix */

div ={1 2 4  6	8 10};  
new = class / div;

/* if you need to print or use as matrices, use SHAPE: */
do i = 1 to nMatrices;
   newM = shape(new, nr, nc);
   print newM;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Although I don't recommend it, if you insist on using symbols that have numerical suffixes, you can &lt;A href="https://blogs.sas.com/content/iml/2011/03/23/indirect-assignment-how-to-create-and-use-matrices-named-x1-x2-xn.html" target="_self"&gt;use the VALUE and VALSET&amp;nbsp;functions.&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do i = 1 to 2;
   cName = "class_" + strip(char(i));
   c = value(cName);    /* get value of class_i */
   new = c / div;
   print new;
   /* if necessary, use VALSET to create new_i */
end;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Mar 2018 21:24:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Using-Loop-Index-in-Name/m-p/443061#M4051</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-03-06T21:24:02Z</dc:date>
    </item>
  </channel>
</rss>

