<?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: Array algebra in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Array-algebra/m-p/312808#M67870</link>
    <description>&lt;P&gt;If you have any sample data, look at next link and try to create any initial code that might do what you want.&lt;/P&gt;
&lt;P&gt;If you have difficulties, post your code to the forum and you will get help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/Array-help/td-p/298434" target="_self"&gt;https://communities.sas.com/t5/Base-SAS-Programming/Array-help/td-p/298434&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Treat this link as a demo for how to write a data step and how to define and use arrays in sas.&lt;/P&gt;</description>
    <pubDate>Sat, 19 Nov 2016 16:05:51 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2016-11-19T16:05:51Z</dc:date>
    <item>
      <title>Array algebra</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-algebra/m-p/312796#M67864</link>
      <description>&lt;P&gt;how can I write a simple code for array (matrix) algebra, this are my input information&lt;/P&gt;&lt;P&gt;y and yhat&amp;nbsp;are the arrays with one column and "n" observation&amp;nbsp;&lt;BR /&gt;the process is repeating k times ( i = 1,...k) and for each run we have different y &amp;amp; yhat,&amp;nbsp;&lt;BR /&gt;for each run the "mean absolute&amp;nbsp;difference" between y &amp;amp; yhat&amp;nbsp;should save in "m".&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;m{i} = sum(of abs(y - yhat));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I don't want to use any proc, how can I write a simple code??&lt;/P&gt;</description>
      <pubDate>Sat, 19 Nov 2016 12:45:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-algebra/m-p/312796#M67864</guid>
      <dc:creator>Marzi</dc:creator>
      <dc:date>2016-11-19T12:45:09Z</dc:date>
    </item>
    <item>
      <title>Re: Array algebra</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-algebra/m-p/312799#M67866</link>
      <description>&lt;P&gt;So&amp;nbsp;you want to do this inside a data step? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 19 Nov 2016 13:30:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-algebra/m-p/312799#M67866</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2016-11-19T13:30:25Z</dc:date>
    </item>
    <item>
      <title>Re: Array algebra</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-algebra/m-p/312804#M67868</link>
      <description>&lt;P&gt;If you want to do matrix calculations your best off switching to SAS IML.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you really haven't told us much. Depending on your data a simple datastep may also suffice. Please post sample data and expected output if you want sample code.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 19 Nov 2016 14:28:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-algebra/m-p/312804#M67868</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-19T14:28:54Z</dc:date>
    </item>
    <item>
      <title>Re: Array algebra</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-algebra/m-p/312808#M67870</link>
      <description>&lt;P&gt;If you have any sample data, look at next link and try to create any initial code that might do what you want.&lt;/P&gt;
&lt;P&gt;If you have difficulties, post your code to the forum and you will get help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/Array-help/td-p/298434" target="_self"&gt;https://communities.sas.com/t5/Base-SAS-Programming/Array-help/td-p/298434&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Treat this link as a demo for how to write a data step and how to define and use arrays in sas.&lt;/P&gt;</description>
      <pubDate>Sat, 19 Nov 2016 16:05:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-algebra/m-p/312808#M67870</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-11-19T16:05:51Z</dc:date>
    </item>
    <item>
      <title>Re: Array algebra</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-algebra/m-p/312825#M67876</link>
      <description>&lt;P&gt;For the DATA step solution, sort by the grouping variable and use a BY statement to accumulate the absolute residuals.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you mentioned&amp;nbsp;matrix algebra, I'll give a SAS/IML solution, which uses the &lt;A href="http://blogs.sas.com/content/iml/2011/11/01/the-unique-loc-trick-a-real-treat.html" target="_self"&gt;UNIQUE-LOC technique&lt;/A&gt; to loop over the groups:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc glm data=sashelp.class plots=none;
class sex;
model weight = height;
output predicted=yhat out=have(rename=(weight=y sex=grp) ); 
run;

proc iml;
use have;
read all var {grp y yhat};
close;

r = abs(y-yhat);
u = unique(grp);
sum  = j(1, ncol(u));
do i = 1 to ncol(u);
   idx = loc(grp = u[i]);
   sum[i] = sum(r[idx]);
end;
print sum[colname=u];
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you have huge data or many groups, it is more efficient to use the &lt;A href="http://blogs.sas.com/content/iml/2011/11/07/an-efficient-alternative-to-the-unique-loc-technique.html" target="_self"&gt;UNIQUEBY tecnique&lt;/A&gt; to loop over the groups.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 19 Nov 2016 20:23:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-algebra/m-p/312825#M67876</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-11-19T20:23:26Z</dc:date>
    </item>
  </channel>
</rss>

