<?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 How to sum along row? in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-sum-along-row/m-p/1576#M504</link>
    <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
Is there a way to add a column that would provide sum of values of columns (say there are 200 columns) along the row? For example, to add a new column of 'Sum' below?&lt;BR /&gt;
&lt;BR /&gt;
Example&lt;BR /&gt;
&lt;BR /&gt;
A B C D E Sum&lt;BR /&gt;
2 2 5 1 0 10&lt;BR /&gt;
..&lt;BR /&gt;
..</description>
    <pubDate>Tue, 17 Oct 2006 23:50:44 GMT</pubDate>
    <dc:creator>SMR</dc:creator>
    <dc:date>2006-10-17T23:50:44Z</dc:date>
    <item>
      <title>How to sum along row?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-sum-along-row/m-p/1576#M504</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
Is there a way to add a column that would provide sum of values of columns (say there are 200 columns) along the row? For example, to add a new column of 'Sum' below?&lt;BR /&gt;
&lt;BR /&gt;
Example&lt;BR /&gt;
&lt;BR /&gt;
A B C D E Sum&lt;BR /&gt;
2 2 5 1 0 10&lt;BR /&gt;
..&lt;BR /&gt;
..</description>
      <pubDate>Tue, 17 Oct 2006 23:50:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-sum-along-row/m-p/1576#M504</guid>
      <dc:creator>SMR</dc:creator>
      <dc:date>2006-10-17T23:50:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum along row?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-sum-along-row/m-p/1577#M505</link>
      <description>data test;&lt;BR /&gt;
infile cards;&lt;BR /&gt;
input A1 A2 A3 A4 A5;&lt;BR /&gt;
cards;&lt;BR /&gt;
2 2 5 1 0&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data test2;&lt;BR /&gt;
set test;&lt;BR /&gt;
sum = sum (of a1-a5);&lt;BR /&gt;
run;</description>
      <pubDate>Wed, 18 Oct 2006 01:54:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-sum-along-row/m-p/1577#M505</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2006-10-18T01:54:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum along row?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-sum-along-row/m-p/1578#M506</link>
      <description>Hi Dan,&lt;BR /&gt;
&lt;BR /&gt;
Could pl. suggest it in using Enterprise Guide? (Not in the programming code,I don't understand the codes at this moment). Thanks&lt;BR /&gt;
Regards,</description>
      <pubDate>Wed, 18 Oct 2006 03:02:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-sum-along-row/m-p/1578#M506</guid>
      <dc:creator>SMR</dc:creator>
      <dc:date>2006-10-18T03:02:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum along row?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-sum-along-row/m-p/1579#M507</link>
      <description>&lt;P&gt;First suggestion, using DATA step and the SUM function:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
infile cards;
input A1 A2 A3 A4 A5;
cards;
2 2 5 1 0
;
run;

data sums;
 set test;

 /* method 1: array of all numerics */
 array n {*} _numeric_;
 sum_allnum=sum(of n[*]);

 /*method 2: variable range in data set */
 sum_range=sum(of a1-a5);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If using EG and you want this in the Query Builder (SQL), you need to add a new computed column.&lt;/P&gt;
&lt;P&gt;Its formula is SUM(var1, var2, var3, ...)&lt;BR /&gt; (you name each and every variable to sum, and separate them with commas).&lt;BR /&gt; Unfortunately the previous shortcut SUM(OF var1-var10) only works in datasteps and EG does not code them for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/8555i1C5F472DD3C8E586/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="cc.png" title="cc.png" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 12:20:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-sum-along-row/m-p/1579#M507</guid>
      <dc:creator>Olivier</dc:creator>
      <dc:date>2017-04-26T12:20:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum along row?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-sum-along-row/m-p/1580#M508</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hey can you please tell me how to sum all the columns with different names....i.e. not a1,a2,a3,a4....but a,b,c,d,....&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Krishan Avtar Singh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Jan 2015 05:43:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-sum-along-row/m-p/1580#M508</guid>
      <dc:creator>KrishanAvtarSingh</dc:creator>
      <dc:date>2015-01-29T05:43:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum along row?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-sum-along-row/m-p/254290#M17856</link>
      <description>&lt;P&gt;Use above formula but replace var1,var2,etc. with column name&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2016 19:03:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-sum-along-row/m-p/254290#M17856</guid>
      <dc:creator>imld</dc:creator>
      <dc:date>2016-03-03T19:03:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum along row?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-sum-along-row/m-p/424494#M27346</link>
      <description>&lt;P&gt;Hello - I had a related question.&amp;nbsp; Since the below is in a data step, how do you get the actual numeric sum?&amp;nbsp; When I did proc freq below, sas gave me the list of values and not the actual sum.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data; set;
sum_range=sum(of a1-a5);
run;&lt;BR /&gt;&lt;BR /&gt;proc freq; tables sum_range; run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Laura&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 02:09:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-sum-along-row/m-p/424494#M27346</guid>
      <dc:creator>lmyers2</dc:creator>
      <dc:date>2018-01-03T02:09:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum along row?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-sum-along-row/m-p/514468#M32545</link>
      <description>&lt;P&gt;I want to sum of only positive numbers then how to do it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for example I have 200 odd variables columns and values like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;a&amp;nbsp; &amp;nbsp;b&amp;nbsp; &amp;nbsp;c ....&amp;nbsp; n&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; -2&amp;nbsp; &amp;nbsp;1...&amp;nbsp; &amp;nbsp; 2&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp;-4...&amp;nbsp; -1&lt;/P&gt;&lt;P&gt;and I want only positive sum of variables like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;a&amp;nbsp; &amp;nbsp;b&amp;nbsp; &amp;nbsp;c ....&amp;nbsp; n&amp;nbsp; &amp;nbsp;PositiveSum&lt;/P&gt;&lt;P&gt;1&amp;nbsp; -2&amp;nbsp; &amp;nbsp;1...&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp;-4...&amp;nbsp; -1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Mon, 19 Nov 2018 15:22:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-sum-along-row/m-p/514468#M32545</guid>
      <dc:creator>ashish112</dc:creator>
      <dc:date>2018-11-19T15:22:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum along row?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-sum-along-row/m-p/621215#M35463</link>
      <description>&lt;P&gt;Replying to Kishan Avtar,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi, you can use the same techniques shown above with slight modification;&lt;/P&gt;&lt;PRE&gt;for defining array,&lt;BR /&gt;array n {*} A--D;   /* or array n(*) _numeric_; */&lt;BR /&gt;sum_allnum=sum(of n[*]);&lt;BR /&gt;..&lt;BR /&gt;for direct approach,&lt;BR /&gt;sum = sum (of A--D); /*sum(of _numeric_)*/&lt;/PRE&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/23201"&gt;@KrishanAvtarSingh&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;hey can you please tell me how to sum all the columns with different names....i.e. not a1,a2,a3,a4....but a,b,c,d,....&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Krishan Avtar Singh&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2020 16:47:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-sum-along-row/m-p/621215#M35463</guid>
      <dc:creator>Nikit7</dc:creator>
      <dc:date>2020-01-30T16:47:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to sum along row?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-sum-along-row/m-p/621302#M35468</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/247321"&gt;@ashish112&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;I want to sum of only positive numbers then how to do it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for example I have 200 odd variables columns and values like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;a&amp;nbsp; &amp;nbsp;b&amp;nbsp; &amp;nbsp;c ....&amp;nbsp; n&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; -2&amp;nbsp; &amp;nbsp;1...&amp;nbsp; &amp;nbsp; 2&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp;-4...&amp;nbsp; -1&lt;/P&gt;&lt;P&gt;and I want only positive sum of variables like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;a&amp;nbsp; &amp;nbsp;b&amp;nbsp; &amp;nbsp;c ....&amp;nbsp; n&amp;nbsp; &amp;nbsp;PositiveSum&lt;/P&gt;&lt;P&gt;1&amp;nbsp; -2&amp;nbsp; &amp;nbsp;1...&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp;-4...&amp;nbsp; -1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;PRE&gt;data test;&lt;BR /&gt;infile cards;&lt;BR /&gt;input A1 A2 A3 A4 A5;&lt;BR /&gt;cards;&lt;BR /&gt;-2 2 5 1 0&lt;BR /&gt;1 -2 5 1 2&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc print;&lt;BR /&gt;data sums;&lt;BR /&gt; set test;&lt;BR /&gt; array n(*) A:;&lt;BR /&gt; do i=1 to dim(n);&lt;BR /&gt; if n[i]&amp;lt;0 then n[i]=0;&lt;BR /&gt; sum=sum(of n(*));&lt;BR /&gt; end;&lt;BR /&gt;run;&lt;BR /&gt;proc print;&lt;BR /&gt;run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Jan 2020 20:15:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-sum-along-row/m-p/621302#M35468</guid>
      <dc:creator>Nikit7</dc:creator>
      <dc:date>2020-01-30T20:15:31Z</dc:date>
    </item>
  </channel>
</rss>

