<?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: Matrix diagonal  operation in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-diagonal-operation/m-p/438008#M4012</link>
    <description>&lt;P&gt;Excellent. Great stuff.&lt;/P&gt;</description>
    <pubDate>Fri, 16 Feb 2018 16:04:33 GMT</pubDate>
    <dc:creator>akpattnaik</dc:creator>
    <dc:date>2018-02-16T16:04:33Z</dc:date>
    <item>
      <title>Matrix diagonal  operation</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-diagonal-operation/m-p/437261#M4001</link>
      <description>&lt;P&gt;Hi Guys,&lt;/P&gt;&lt;P&gt;I’m in process of converting an excel report into sas proc iml code.&lt;/P&gt;&lt;P&gt;I have to achieve the below, can anyone give me a hand please?&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;For all diagonal values I want to get 1.&lt;/LI&gt;&lt;LI&gt;For non-diagonal values, divide the respective values by column total. If division ends in error populate value 0.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;Attached in the sample data set.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Feb 2018 18:28:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-diagonal-operation/m-p/437261#M4001</guid>
      <dc:creator>akpattnaik</dc:creator>
      <dc:date>2018-02-14T18:28:54Z</dc:date>
    </item>
    <item>
      <title>Re: Matrix diagonal  operation</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-diagonal-operation/m-p/437476#M4003</link>
      <description>&lt;P&gt;I think this will do what you want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;

   x = {1 . 3, 4 5 6, -5 4 1};
   n = nrow(x);
   y = x / x[+, ];        /* divide by zero warnings in log */
   y[do(1,n#n,n+1)] = 1;  /* set diagonal to 1 */
   idx = loc(y=.);        /* find any missing values and replace with zero */
   if ncol(idx)&amp;gt;0 then y[idx] = 0;

   print x, y;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I have set up the first column of x to have a sum of zero, this generates missing values in the first column of y&amp;nbsp;which are then replaced with zero.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 10:02:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-diagonal-operation/m-p/437476#M4003</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2018-02-15T10:02:36Z</dc:date>
    </item>
    <item>
      <title>Re: Matrix diagonal  operation</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-diagonal-operation/m-p/437670#M4009</link>
      <description>&lt;P&gt;Hi Ian,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A quick question. I want to check a condition .i.e. if the value is not zero then set the diagonal to 1.&lt;/P&gt;&lt;P&gt;I tried a lot but couldn't find what needs to be done to the below. Any help will really be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;  y&lt;SPAN class="token punctuation"&gt;[&lt;/SPAN&gt;do&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;n&lt;/SPAN&gt;#&lt;SPAN class="token function"&gt;n&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;n&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;+&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;]&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;  &lt;SPAN class="token comment"&gt;/* set diagonal to 1 */&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 16:20:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-diagonal-operation/m-p/437670#M4009</guid>
      <dc:creator>akpattnaik</dc:creator>
      <dc:date>2018-02-15T16:20:51Z</dc:date>
    </item>
    <item>
      <title>Re: Matrix diagonal  operation</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-diagonal-operation/m-p/437690#M4010</link>
      <description>&lt;P&gt;I think the following is what you need:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;y[do(1,n#n,n+1)] = vecdiag(y)^=.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which sets the diagonal to 1 wherever it is non-missing after the division, otherwise it is set to zero.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 16:51:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-diagonal-operation/m-p/437690#M4010</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2018-02-15T16:51:18Z</dc:date>
    </item>
    <item>
      <title>Re: Matrix diagonal  operation</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-diagonal-operation/m-p/438008#M4012</link>
      <description>&lt;P&gt;Excellent. Great stuff.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2018 16:04:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-diagonal-operation/m-p/438008#M4012</guid>
      <dc:creator>akpattnaik</dc:creator>
      <dc:date>2018-02-16T16:04:33Z</dc:date>
    </item>
    <item>
      <title>Re: Matrix diagonal  operation</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-diagonal-operation/m-p/438393#M4022</link>
      <description>&lt;P&gt;Hi Ian,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Trust you well. Just wondering if you can help with the below:&lt;/P&gt;&lt;P&gt;Now instead&amp;nbsp;of 1 on the diagonal, i want 1- a matrix element.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="  language-sas"&gt;&lt;CODE class="  language-sas"&gt;y&lt;SPAN class="token punctuation"&gt;[&lt;/SPAN&gt;do&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;n&lt;/SPAN&gt;#&lt;SPAN class="token function"&gt;n&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;n&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;+&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;]&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; 1- AR; (where AR is a matrix, of same shape)&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE class="  language-sas"&gt;&lt;CODE class="  language-sas"&gt;y&lt;SPAN class="token punctuation"&gt;[&lt;/SPAN&gt;do&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;n&lt;/SPAN&gt;#&lt;SPAN class="token function"&gt;n&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;n&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;+&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;]&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; (&lt;SPAN class="token number"&gt;1- AR); &lt;BR /&gt;Both doesn't work. I get a error - "Matrix do not conform to the operation"&lt;BR /&gt;Any idea?&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE class="  language-sas"&gt;&lt;CODE class="  language-sas"&gt;&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Feb 2018 13:32:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-diagonal-operation/m-p/438393#M4022</guid>
      <dc:creator>akpattnaik</dc:creator>
      <dc:date>2018-02-19T13:32:14Z</dc:date>
    </item>
    <item>
      <title>Re: Matrix diagonal  operation</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-diagonal-operation/m-p/438397#M4023</link>
      <description>&lt;P&gt;The left hand side is referring only to the diagonal elements, while the right hand side contains n^2 elements this is the reason for the non-conforming error message.&amp;nbsp; The solution is to extract only the diagonal element of AR using the vecdiag function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;y[do(1,n#n,n+1)] = 1 - vecdiag(AR);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Feb 2018 13:49:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-diagonal-operation/m-p/438397#M4023</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2018-02-19T13:49:20Z</dc:date>
    </item>
    <item>
      <title>Re: Matrix diagonal  operation</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-diagonal-operation/m-p/438401#M4024</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;a Ton Ian. You are a&amp;nbsp;genius!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;</description>
      <pubDate>Mon, 19 Feb 2018 14:18:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Matrix-diagonal-operation/m-p/438401#M4024</guid>
      <dc:creator>akpattnaik</dc:creator>
      <dc:date>2018-02-19T14:18:14Z</dc:date>
    </item>
  </channel>
</rss>

