<?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: Difference between sum(x+y) and sum(x,y) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-sum-x-y-and-sum-x-y/m-p/479503#M123801</link>
    <description>&lt;P&gt;You are using two different functions. The normal SAS function SUM(,) takes two or more arguments and will add them together (ignoring missing values).&amp;nbsp; There many other similar functions that SAS has for this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The SQL aggregate function SUM() will aggregate, in this case sum,&amp;nbsp; its single argument across all observations (or all observations within a group if your statement includes a GROUP BY clause).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looks like you want to use BOTH of them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select sum( sum(x,y) ) as Total_X_and_Y
from have
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 19 Jul 2018 13:56:04 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-07-19T13:56:04Z</dc:date>
    <item>
      <title>Difference between sum(x+y) and sum(x,y)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-sum-x-y-and-sum-x-y/m-p/479498#M123799</link>
      <description>&lt;P&gt;Hi, All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've noticed a difference between these two syntaxes and I was wondering if somebody could explain the difference to me.&lt;/P&gt;&lt;P&gt;If I run&amp;nbsp; the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table output&lt;BR /&gt;as select id,&lt;BR /&gt;sub_id,&lt;BR /&gt;sum(col_x+col_y) as col_z&lt;BR /&gt;from input&lt;BR /&gt;group by id&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;col_z will be summed across the rows AND for the grouped variable.&amp;nbsp; However, if I run this proc sql with sum(col_x,col_y) then the sum will be calculated across the rows but NOT for the grouped variable.&amp;nbsp; So why is there a difference between these two?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance for any help you can offer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jul 2018 13:50:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-sum-x-y-and-sum-x-y/m-p/479498#M123799</guid>
      <dc:creator>boyandhisrobot</dc:creator>
      <dc:date>2018-07-19T13:50:10Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between sum(x+y) and sum(x,y)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-sum-x-y-and-sum-x-y/m-p/479503#M123801</link>
      <description>&lt;P&gt;You are using two different functions. The normal SAS function SUM(,) takes two or more arguments and will add them together (ignoring missing values).&amp;nbsp; There many other similar functions that SAS has for this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The SQL aggregate function SUM() will aggregate, in this case sum,&amp;nbsp; its single argument across all observations (or all observations within a group if your statement includes a GROUP BY clause).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looks like you want to use BOTH of them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select sum( sum(x,y) ) as Total_X_and_Y
from have
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Jul 2018 13:56:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-sum-x-y-and-sum-x-y/m-p/479503#M123801</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-07-19T13:56:04Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between sum(x+y) and sum(x,y)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-sum-x-y-and-sum-x-y/m-p/479505#M123802</link>
      <description>&lt;P&gt;Thanks, Tom.&amp;nbsp; That clears it up.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jul 2018 13:58:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-sum-x-y-and-sum-x-y/m-p/479505#M123802</guid>
      <dc:creator>boyandhisrobot</dc:creator>
      <dc:date>2018-07-19T13:58:10Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between sum(x+y) and sum(x,y)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-sum-x-y-and-sum-x-y/m-p/479512#M123804</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is how sum function works-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sum (1, 2, ., 3) = 6,&amp;nbsp; &amp;nbsp; &lt;STRONG&gt;==&amp;gt;&lt;/STRONG&gt; means when we use ' &lt;STRONG&gt;,&lt;/STRONG&gt; ' in sum function it ignores the missing value and sum the other values.&lt;/P&gt;&lt;P&gt;Sum (1 + 2 + . +3) = . (missing),&amp;nbsp; &amp;nbsp; &lt;STRONG&gt;==&amp;gt;&lt;/STRONG&gt; means when we use '+' in sum function it considers 'missing + Value = missing' .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jul 2018 14:18:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-sum-x-y-and-sum-x-y/m-p/479512#M123804</guid>
      <dc:creator>vishalrajpoot3</dc:creator>
      <dc:date>2018-07-19T14:18:13Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between sum(x+y) and sum(x,y)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-sum-x-y-and-sum-x-y/m-p/479515#M123806</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/214824"&gt;@vishalrajpoot3&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is how sum function works-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sum (1, 2, ., 3) = 6,&amp;nbsp; &amp;nbsp; &lt;STRONG&gt;==&amp;gt;&lt;/STRONG&gt; means when we use ' &lt;STRONG&gt;,&lt;/STRONG&gt; ' in sum function it ignores the missing value and sum the other values.&lt;/P&gt;
&lt;P&gt;Sum (1 + 2 + . +3) = . (missing),&amp;nbsp; &amp;nbsp; &lt;STRONG&gt;==&amp;gt;&lt;/STRONG&gt; means when we use '+' in sum function it considers 'missing + Value = missing' .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You are talking about the difference between the SUM(,) function and just simple addition.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;sum(x,y,z)
vs
x+y+z&lt;/PRE&gt;
&lt;P&gt;If you use your second expression inside of PROC SQL then it will use the SQL aggregate function SUM() instead of the SAS function SUM(,) that the first expression is using.&amp;nbsp; If you want to force it to use the SAS function then add a second argument.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;sum(x+y+z,.)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Jul 2018 14:27:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-sum-x-y-and-sum-x-y/m-p/479515#M123806</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-07-19T14:27:16Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between sum(x+y) and sum(x,y)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-sum-x-y-and-sum-x-y/m-p/479521#M123809</link>
      <description>yes Tom, you are right, it shows only difference. I am at bragging stage of learning SAS, so I just tried to give a part of solution.</description>
      <pubDate>Thu, 19 Jul 2018 14:32:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-sum-x-y-and-sum-x-y/m-p/479521#M123809</guid>
      <dc:creator>vishalrajpoot3</dc:creator>
      <dc:date>2018-07-19T14:32:31Z</dc:date>
    </item>
  </channel>
</rss>

