<?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: Proc IML: USe a matrix as an index to another matrix. in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-USe-a-matrix-as-an-index-to-another-matrix/m-p/607273#M4923</link>
    <description>&lt;P&gt;yes thank you very concise&lt;/P&gt;</description>
    <pubDate>Tue, 26 Nov 2019 11:17:30 GMT</pubDate>
    <dc:creator>Sanscrit_2prov</dc:creator>
    <dc:date>2019-11-26T11:17:30Z</dc:date>
    <item>
      <title>Proc IML: USe a matrix as an index to another matrix.</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-USe-a-matrix-as-an-index-to-another-matrix/m-p/606979#M4919</link>
      <description>&lt;P&gt;I am trying to create a 3 x13 matrix called it deaths, that contains the sum of the number of deaths for each of three years.&lt;/P&gt;&lt;P&gt;The matrix called outcome is a column vector with each row containing 1 to 3 years of observations for each person. Let's say there are 1,000 rows.&amp;nbsp;The matrix called time also has 1,000 rows, but in addition, each of 3 columns contains an indicator for whether the record is from time 1 (col 1), time 2 (col 2) and time 3 (col 3).&amp;nbsp; &amp;nbsp;I want to sum the deaths in outcome for each individual year. That is, I want to use the indicator in the time matrix to sum those specific rows in the outcome matrix.&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;Outcome is first column below. time (col1) time (col 2) time (col3) are the columns of the time matrix...&lt;/P&gt;&lt;P&gt;row 1 0&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; 0&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;row 2 0&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; 1&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;row 3 0&amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; 0&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;row4&amp;nbsp; 0&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp;0&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;row 5 1&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp;1&amp;nbsp; 0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So the matrix that I want called deaths would sum row 1 and 4, row 2 and 5, to reflect the one and two years totala,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I use the following code that does not work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;deaths=j(3,1,0);&lt;BR /&gt;do yr=1 to 3;&lt;/P&gt;&lt;P&gt;deaths[yr]=sum(outcome[time[yr]=1,]));&lt;/P&gt;&lt;P&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;Does anyone have a suggestion basically for using a matrix to select specific rows from another matrix.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 25 Nov 2019 14:29:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-USe-a-matrix-as-an-index-to-another-matrix/m-p/606979#M4919</guid>
      <dc:creator>Sanscrit_2prov</dc:creator>
      <dc:date>2019-11-25T14:29:33Z</dc:date>
    </item>
    <item>
      <title>Re: Proc IML: USe a matrix as an index to another matrix.</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-USe-a-matrix-as-an-index-to-another-matrix/m-p/606983#M4920</link>
      <description>&lt;P&gt;I am guessing a little, but is the missing ingredient the LOC function? &amp;nbsp; So you would need something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;deaths[yr]=sum(outcome[ loc(time[ ,yr]=1) ,]));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Nov 2019 14:40:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-USe-a-matrix-as-an-index-to-another-matrix/m-p/606983#M4920</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2019-11-25T14:40:19Z</dc:date>
    </item>
    <item>
      <title>Re: Proc IML: USe a matrix as an index to another matrix.</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-USe-a-matrix-as-an-index-to-another-matrix/m-p/606985#M4921</link>
      <description>&lt;P&gt;I assume there is a typo in the first sentence and you want a 3x1 matrix.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It sounds like you need to&lt;A href="https://blogs.sas.com/content/iml/2011/05/16/finding-data-that-satisfy-a-criterion.html" target="_self"&gt; use the LOC function to find the rows for each year&lt;/A&gt;. Then (&lt;A href="https://blogs.sas.com/content/iml/2012/11/19/beware-the-naked-loc.html" target="_self"&gt;if any rows were found&lt;/A&gt;), use those row indices to subset the OUTCOME variable. The links provide more information and examples.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
outcome = {0,0,0,0,1};
time = {1 0 0,
        0 1 0,
        0 0 1,
        1 0 0,
        0 1 0};

deaths=j(3,1,0);
do yr=1 to 3;
   idx = loc(time[,yr]=1);    /* find 1s in each column */
   if ncol(idx) &amp;gt; 0 then do;  /* were any 1s found? */
      print yr idx;
      deaths[yr]=sum(outcome[idx]);  /* sum the corresponding rows of the OUTCOME variable */
   end;
end;
print deaths;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Nov 2019 14:45:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-USe-a-matrix-as-an-index-to-another-matrix/m-p/606985#M4921</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2019-11-25T14:45:46Z</dc:date>
    </item>
    <item>
      <title>Re: Proc IML: USe a matrix as an index to another matrix.</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-USe-a-matrix-as-an-index-to-another-matrix/m-p/607054#M4922</link>
      <description>&lt;P&gt;Thank you so much. This is a nice concise section of code.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Nov 2019 16:45:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-USe-a-matrix-as-an-index-to-another-matrix/m-p/607054#M4922</guid>
      <dc:creator>Sanscrit_2prov</dc:creator>
      <dc:date>2019-11-25T16:45:50Z</dc:date>
    </item>
    <item>
      <title>Re: Proc IML: USe a matrix as an index to another matrix.</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-USe-a-matrix-as-an-index-to-another-matrix/m-p/607273#M4923</link>
      <description>&lt;P&gt;yes thank you very concise&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 11:17:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-USe-a-matrix-as-an-index-to-another-matrix/m-p/607273#M4923</guid>
      <dc:creator>Sanscrit_2prov</dc:creator>
      <dc:date>2019-11-26T11:17:30Z</dc:date>
    </item>
  </channel>
</rss>

