<?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 iterative do loop sum in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-iterative-do-loop-sum/m-p/352856#M3460</link>
    <description>&lt;P&gt;Wow that is some witchcraft! I can't believe how simple that is. &amp;nbsp;Could you explain the syntax? &amp;nbsp;Particularly what the backtick symbol does in this situation, and how [,+] works?&lt;/P&gt;</description>
    <pubDate>Mon, 24 Apr 2017 13:51:22 GMT</pubDate>
    <dc:creator>dsriggs</dc:creator>
    <dc:date>2017-04-24T13:51:22Z</dc:date>
    <item>
      <title>Proc IML iterative do loop sum</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-iterative-do-loop-sum/m-p/352806#M3456</link>
      <description>&lt;P&gt;I have a problem I am trying to solve using a do loop with proc iml. &amp;nbsp;What I am trying to do is take each data point from column "y" one at a time, and multiply it by the vector x, and create a column "z" which is the sum of&amp;nbsp;each iteration of the loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
input x y;
datalines;
1 2
3 6
5 10
7 14
9 18
;

proc iml;
use work.example;
read all var{x} into x;
do i=1 to 5;
read point i var{y} into y;
z=x*y;
end;
print z;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;For example if I run this it will give me the z output as:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;18&lt;/P&gt;&lt;P&gt;54&lt;/P&gt;&lt;P&gt;90&lt;/P&gt;&lt;P&gt;126&lt;/P&gt;&lt;P&gt;162&lt;/P&gt;&lt;P&gt;This is just taking the last iteration of the loop with y=18 and multiplying by the "x" column. &amp;nbsp;What I am trying to do is get results like:&lt;/P&gt;&lt;P&gt;z&lt;/P&gt;&lt;P&gt;2+6+10+14+18=50 (first iteration)&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;18+54+90+126+162=450 (last iteration)&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2017 12:18:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-iterative-do-loop-sum/m-p/352806#M3456</guid>
      <dc:creator>dsriggs</dc:creator>
      <dc:date>2017-04-24T12:18:40Z</dc:date>
    </item>
    <item>
      <title>Re: Proc IML iterative do loop sum</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-iterative-do-loop-sum/m-p/352810#M3457</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
input x y;
datalines;
1 2
3 6
5 10
7 14
9 18
;

PROC SQL;
CREATE TABLE MYJOIN AS
SELECT EXAMPLE1.X, EXAMPLE2.Y, EXAMPLE1.X * EXAMPLE2.Y AS MULT
FROM EXAMPLE AS EXAMPLE1, EXAMPLE AS EXAMPLE2;
QUIT;

PROC SQL;
CREATE TABLE SUMS AS
SELECT MYJOIN.X, SUM(MULT) AS TOTAL FROM MYJOIN GROUP BY MYJOIN.X;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Apr 2017 12:27:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-iterative-do-loop-sum/m-p/352810#M3457</guid>
      <dc:creator>thomp7050</dc:creator>
      <dc:date>2017-04-24T12:27:26Z</dc:date>
    </item>
    <item>
      <title>Re: Proc IML iterative do loop sum</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-iterative-do-loop-sum/m-p/352828#M3458</link>
      <description>&lt;PRE&gt;
How about this one .



data example;
input x y;
datalines;
1 2
3 6
5 10
7 14
9 18
;

proc iml;
use work.example;
read all var{x y} ;
close;
z=(y*x`)[,+];

print z;
quit;


&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Apr 2017 12:58:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-iterative-do-loop-sum/m-p/352828#M3458</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-04-24T12:58:09Z</dc:date>
    </item>
    <item>
      <title>Re: Proc IML iterative do loop sum</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-iterative-do-loop-sum/m-p/352843#M3459</link>
      <description>&lt;P&gt;I like KSharp's solution, which doesn't require a loop. &amp;nbsp;If you are required to use a loop (maybe for a homework assignment or because this is a simplification of a more complicated computation), the following program shows how to iterate over the elements of x to form each element of z:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
use work.example;
read all var {x y};      /* read all data */
close;
z = j(nrow(x),1,.);      /* allocate result vector */
do i=1 to nrow(x);
   z[i] = sum(x[i] * y); 
end;
print z;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;KSarp's solution uses a concept called "vectorizing" a program. For more about how to vectorize a SAS/IML program, see the article &lt;A href="http://blogs.sas.com/content/iml/2013/05/15/vectorize-computations.html" target="_self"&gt;"How to vectorize computations in a matrix language."&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2017 13:33:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-iterative-do-loop-sum/m-p/352843#M3459</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-04-24T13:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: Proc IML iterative do loop sum</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-iterative-do-loop-sum/m-p/352856#M3460</link>
      <description>&lt;P&gt;Wow that is some witchcraft! I can't believe how simple that is. &amp;nbsp;Could you explain the syntax? &amp;nbsp;Particularly what the backtick symbol does in this situation, and how [,+] works?&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2017 13:51:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-iterative-do-loop-sum/m-p/352856#M3460</guid>
      <dc:creator>dsriggs</dc:creator>
      <dc:date>2017-04-24T13:51:22Z</dc:date>
    </item>
    <item>
      <title>Re: Proc IML iterative do loop sum</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-iterative-do-loop-sum/m-p/352876#M3461</link>
      <description>&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;x &amp;nbsp; y&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; 4&lt;/P&gt;
&lt;P&gt;2 &amp;nbsp; 5&lt;/P&gt;
&lt;P&gt;3 &amp;nbsp; 6&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;` means transpose operator&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;y*x` =&lt;/P&gt;
&lt;P&gt;4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4 8 12&lt;/P&gt;
&lt;P&gt;5 &amp;nbsp; &amp;nbsp;* &amp;nbsp; 1 2 3 &amp;nbsp; &amp;nbsp;= &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5 10 15&lt;/P&gt;
&lt;P&gt;6 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6 12 18&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;[,+] &amp;nbsp;mean sum each row &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;4 8 12 &amp;nbsp; = 24&lt;/P&gt;
&lt;P&gt;.......&lt;/P&gt;
&lt;P&gt;.......&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2017 14:34:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Proc-IML-iterative-do-loop-sum/m-p/352876#M3461</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-04-24T14:34:53Z</dc:date>
    </item>
  </channel>
</rss>

