<?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: SAS IML in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/SAS-IML/m-p/386989#M3685</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The matrix 'a' is a data matrix. &amp;nbsp;The "lower triangular portion" of a data matrix is not useful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you compute C=cov(A), then C is a symmetric matrix, so the lower triangular portion is relevant and useful. &amp;nbsp;However, the lower triangular matrix does not have the property that you are trying to claim.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am going to guess that you want the Cholesky decomposition of the covariance matrix, which is the upper triangular matrix U&amp;nbsp;such that C = U` * U. &amp;nbsp;Equivalently, you can define L = U` so that C = L * L`. You can &lt;A href="http://support.sas.com/documentation/cdl/en/imlug/68150/HTML/default/viewer.htm#imlug_langref_sect391.htm" target="_self"&gt;compute the Cholesky matrix by using the ROOT function in SAS/IML&lt;/A&gt;, as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
use a;
   read all var _NUM_ into a;
close;

C = cov(a);
U = root(C);  /* C = U` * U */
L = U`;       /* C = L * L` */

/* test to make sure it works */
C2 = L*L`;
print L, C, C2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 10 Aug 2017 13:39:38 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2017-08-10T13:39:38Z</dc:date>
    <item>
      <title>SAS IML</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/SAS-IML/m-p/386964#M3682</link>
      <description>&lt;P&gt;I searched on line and found the following link:&lt;/P&gt;&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/bring-back-Lower-triangular-matrix/td-p/60714" target="_blank"&gt;https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/bring-back-Lower-triangular-matrix/td-p/60714&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;which discussed&amp;nbsp; calculating the lower triangular matrix.&amp;nbsp; The attached code was provided at the link:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*LOWER TRIANGULAR CODE SAS IML*/

proc import out=a
datafile='/folders/myfolders/dmatrix/lnparam.csv/'
            dbms=csv replace;
            getnames=yes;
            datarow=2;
run;   

proc iml;
/*To get the values in a vector, you can use*/
 lower = symsqr(a);
 upper = symsqr(a`);

/*If you need the lower triangular matrix with zeros above the diagonal, you can use:*/
 n = nrow(a);
 p = ncol(a);
 low = j(n, p, 0);
 do i = 1 to n;
 cols = 1:i; /* or cols=iSmiley Tongue; */
 low[i, cols] = a[i, cols];
 end; 
  quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;When I run the code I get several errors:&amp;nbsp;&lt;/P&gt;&lt;DIV class="sasSource"&gt;/*To get the values in a vector, you can use*/&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;107 lower = symsqr(a);&lt;/DIV&gt;&lt;DIV class="sasError"&gt;ERROR: (execution) Matrix has not been set to a value.&amp;nbsp; I get the same error for a'&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;DIV class="sasSource"&gt;/*If you need the lower triangular matrix with zeros above the diagonal, you can use:*/&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;111 n = nrow(a);&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;112 p = ncol(a);&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;113 low = j(n, p, 0);&lt;/DIV&gt;&lt;DIV class="sasError"&gt;ERROR: (execution) Invalid operand to operation.&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;I have attached my data set lnparam.txt&lt;/DIV&gt;&lt;DIV class="sasError"&gt;Can someone with expertise in SAS IML tell me&amp;nbsp; how to correct the error?&lt;/DIV&gt;&lt;DIV class="sasError"&gt;A final question related to the lower triangle matrix.&amp;nbsp; If one calls the lower triangular matrix D&amp;nbsp; and D' its transpose (i.e., does the&lt;/DIV&gt;&lt;DIV class="sasError"&gt;var cov matrix=DxD')?&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 10 Aug 2017 12:29:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/SAS-IML/m-p/386964#M3682</guid>
      <dc:creator>jacksonan123</dc:creator>
      <dc:date>2017-08-10T12:29:25Z</dc:date>
    </item>
    <item>
      <title>Re: SAS IML</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/SAS-IML/m-p/386968#M3683</link>
      <description>&lt;P&gt;First, could you please edit the title of this thread to make it more informative? Perhaps "How to extract the lower triangular portion of a matrix".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the previous&amp;nbsp;thread&amp;nbsp;that you link to, the responder used&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; a = {1 2 3, 4 5 6, 7 8 9};&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;before&lt;/STRONG&gt; writing the code that you quote. &amp;nbsp;Your problem is that you have not read the data into an IML matrix.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Use&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
use a;
   read all var _NUM_ into a;
close a;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;For more information about reading data sets into SAS/IML matrices, see the article &lt;A href="http://blogs.sas.com/content/iml/2012/01/16/reading-all-variables-into-a-matrix.html" target="_self"&gt;"Reading all variables into a matrix."&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&amp;gt; A final question related to the lower triangle matrix.&amp;nbsp; If one calls the lower triangular matrix D and D' &lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&amp;gt; its transpose,&lt;/EM&gt;&lt;EM&gt;&amp;nbsp;does the var &lt;/EM&gt;cov&lt;EM&gt; matrix=DxD'&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No. You are reading in the data matrix. You can obtain the variance-covariance matrix by using&amp;nbsp;&lt;/P&gt;
&lt;P&gt;C = cov(a);&lt;/P&gt;
&lt;P&gt;You can then get the lower triangular elements of C, if that is important.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2017 12:51:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/SAS-IML/m-p/386968#M3683</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-08-10T12:51:45Z</dc:date>
    </item>
    <item>
      <title>Re: SAS IML</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/SAS-IML/m-p/386985#M3684</link>
      <description>I was able to modify code to read:&lt;BR /&gt;&lt;BR /&gt;proc iml;&lt;BR /&gt;&lt;BR /&gt;use a;&lt;BR /&gt;&lt;BR /&gt;read all var _ALL_ into A;&lt;BR /&gt;&lt;BR /&gt;close a;&lt;BR /&gt;&lt;BR /&gt;show names;&lt;BR /&gt;&lt;BR /&gt;The code read the data in to ( a), however I got an error related to the&lt;BR /&gt;symsqr statement which I looked up which states that it packs the elements&lt;BR /&gt;from the lower triangular portion into a column. The error was:&lt;BR /&gt;&lt;BR /&gt;113 lower = symsqr(a);&lt;BR /&gt;&lt;BR /&gt;ERROR: (execution) Matrix should be square.&lt;BR /&gt;&lt;BR /&gt;How do I address this issue since my matrix is not square?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;There is also an issue with the i subscript which I guess would be related&lt;BR /&gt;to the matrix not being square:&lt;BR /&gt;&lt;BR /&gt;121 cols = 1:i;&lt;BR /&gt;121 ! /* or cols=iSmiley Tongue; */&lt;BR /&gt;122 low[i, cols] = a[i, cols];&lt;BR /&gt;123 end;&lt;BR /&gt;ERROR: (execution) Invalid subscript or subscript out of range.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;How can this issue be resolved?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Based upon your answer related to my final question &amp;gt; does the var cov&lt;BR /&gt;matrix=DxD' I would surmise that&lt;BR /&gt;&lt;BR /&gt;If C=cov(a) then VAR COV=lower triangular C x C'. Would that be correct?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks for your response.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 10 Aug 2017 13:24:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/SAS-IML/m-p/386985#M3684</guid>
      <dc:creator>jacksonan123</dc:creator>
      <dc:date>2017-08-10T13:24:01Z</dc:date>
    </item>
    <item>
      <title>Re: SAS IML</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/SAS-IML/m-p/386989#M3685</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The matrix 'a' is a data matrix. &amp;nbsp;The "lower triangular portion" of a data matrix is not useful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you compute C=cov(A), then C is a symmetric matrix, so the lower triangular portion is relevant and useful. &amp;nbsp;However, the lower triangular matrix does not have the property that you are trying to claim.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am going to guess that you want the Cholesky decomposition of the covariance matrix, which is the upper triangular matrix U&amp;nbsp;such that C = U` * U. &amp;nbsp;Equivalently, you can define L = U` so that C = L * L`. You can &lt;A href="http://support.sas.com/documentation/cdl/en/imlug/68150/HTML/default/viewer.htm#imlug_langref_sect391.htm" target="_self"&gt;compute the Cholesky matrix by using the ROOT function in SAS/IML&lt;/A&gt;, as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
use a;
   read all var _NUM_ into a;
close;

C = cov(a);
U = root(C);  /* C = U` * U */
L = U`;       /* C = L * L` */

/* test to make sure it works */
C2 = L*L`;
print L, C, C2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2017 13:39:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/SAS-IML/m-p/386989#M3685</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-08-10T13:39:38Z</dc:date>
    </item>
    <item>
      <title>Re: SAS IML</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/SAS-IML/m-p/387001#M3686</link>
      <description>&lt;P&gt;Worked just as you stated and the key element was use of the Cholesky matrix and the root function in SAS IML.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2017 13:50:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/SAS-IML/m-p/387001#M3686</guid>
      <dc:creator>jacksonan123</dc:creator>
      <dc:date>2017-08-10T13:50:50Z</dc:date>
    </item>
  </channel>
</rss>

