<?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 Re: Working with matrices in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Working-with-matrices/m-p/291652#M2946</link>
    <description>Thank you for your response; it has been extremely helpful. I am glad to see that I didn't miss a glaringly obvious solution.</description>
    <pubDate>Mon, 15 Aug 2016 08:10:18 GMT</pubDate>
    <dc:creator>DaniDenzel</dc:creator>
    <dc:date>2016-08-15T08:10:18Z</dc:date>
    <item>
      <title>Working with matrices</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Working-with-matrices/m-p/290929#M2942</link>
      <description>&lt;P&gt;I am new to SAS so my knowledge is very basic. I am using SAS version 9.3. I want to create multiple matrices based on a single matrix, V, that I have created. In Stata, the loop is very simple but I do not know how to replicate it in SAS. In Stata, I would write:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;forvalues i=1/23 {&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;mat V`i'=V&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I write this in SAS to produce 23 matrices that are equal to the matrix, V? I want to do this so that I can then manipulate the matrices.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2016 09:50:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Working-with-matrices/m-p/290929#M2942</guid>
      <dc:creator>DaniDenzel</dc:creator>
      <dc:date>2016-08-11T09:50:44Z</dc:date>
    </item>
    <item>
      <title>Re: Working with matrices</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Working-with-matrices/m-p/290935#M2943</link>
      <description>&lt;P&gt;There is no built in way to have&amp;nbsp;an array of matrices in IML, so it may be best to consider storing all&amp;nbsp;the matrices in one large matrix.&amp;nbsp;If the matrices&amp;nbsp;are all the same shape (as in your example)&amp;nbsp;then you could stack them side-by-side or on top of each other and then access each one by subsetting columns or rows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is a way to keep the matrices separate by using the VALSET and VALUE functions, but avoid this if you can as it can make the code difficult to follow.&amp;nbsp;&amp;nbsp;Rick has &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;a nice blog post on this&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2016 10:54:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Working-with-matrices/m-p/290935#M2943</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2016-08-11T10:54:21Z</dc:date>
    </item>
    <item>
      <title>Re: Working with matrices</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Working-with-matrices/m-p/290943#M2944</link>
      <description>Could you post an example (a dummy matrix) to explain what you are looking for ?</description>
      <pubDate>Thu, 11 Aug 2016 11:53:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Working-with-matrices/m-p/290943#M2944</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-08-11T11:53:22Z</dc:date>
    </item>
    <item>
      <title>Re: Working with matrices</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Working-with-matrices/m-p/290958#M2945</link>
      <description>&lt;P&gt;Welcome to SAS. I'm not familiar with that Stata notation, but here are some tips that I hope will help you get started. First, read &lt;A href="http://blogs.sas.com/content/iml/2014/08/11/ten-tips-for-learning-sasiml.html" target="_self"&gt;"Ten tips for learning the SAS/IML language."&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second, let us know what you are trying to accomplish. Different languages have different conventions and strengths/weaknesses. The exact steps to accomplish something in&amp;nbsp;Stata might be difficult to accomplish in another language, but there is often an equivalent set of steps that accomplishes the same thing. &amp;nbsp;Just as idioms in English do not translate verbatim into Spanish, idoms/paradigms in one computer language not translate exactly into another computer language.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is some sample code that might help you. The following program starts with a matrix V. It loops 23 times. For each iteration it creates a new matrix, B. The new matrix starts out being equal to V, but then two values are randomly chosen and swapped.&lt;/P&gt;
&lt;P&gt;The determinant of B is computed and stored in a vector called RESULT:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
V = {1 2 3, 
     3 2 1,
     2 1 3};
/* Loop to compute the determinant of 23 matrices.
   Each matrix is similar to the matrix V, but 
   has two random elements swapped. */
N = 23;
numElements = 9;
result = j(N, 1);     /* allocate array to store results */
do k = 1 to N; 
   B = V;             /* initialize B to V */
   i = sample(1:numElements, 1); /* random integer 1:9 */
   j = sample(1:numElements, 1); /* random integer 1:9 */
   B[i||j] = V[j||i];            /* swap values */
   result[k] = det(B);           /* store result for this iteration */
end;
print result;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Two lessons here:&lt;/P&gt;
&lt;P&gt;1) The matrix B is re-used 23 times. You do not need to create 23 matrices with different names because the result for each iteration&amp;nbsp;is independent.&lt;/P&gt;
&lt;P&gt;2) The results of each iteration are stored in a vector.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is a common way to program an iterative algorithm in SAS/IML. You re-use matrices within a loop and store the results in a vector.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2016 12:51:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Working-with-matrices/m-p/290958#M2945</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-08-11T12:51:40Z</dc:date>
    </item>
    <item>
      <title>Re: Working with matrices</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Working-with-matrices/m-p/291652#M2946</link>
      <description>Thank you for your response; it has been extremely helpful. I am glad to see that I didn't miss a glaringly obvious solution.</description>
      <pubDate>Mon, 15 Aug 2016 08:10:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Working-with-matrices/m-p/291652#M2946</guid>
      <dc:creator>DaniDenzel</dc:creator>
      <dc:date>2016-08-15T08:10:18Z</dc:date>
    </item>
    <item>
      <title>Re: Working with matrices</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Working-with-matrices/m-p/291653#M2947</link>
      <description>Thank you for such a detailed response that has been so helpful to me.&lt;BR /&gt;It is impressive to see such a supportive environment, even for someone that is a beginner like me! So thanks again.</description>
      <pubDate>Mon, 15 Aug 2016 08:14:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Working-with-matrices/m-p/291653#M2947</guid>
      <dc:creator>DaniDenzel</dc:creator>
      <dc:date>2016-08-15T08:14:02Z</dc:date>
    </item>
  </channel>
</rss>

