<?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 summing my sums in proc sql easily in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/summing-my-sums-in-proc-sql-easily/m-p/457003#M115836</link>
    <description>&lt;P&gt;suppose I have a query that is has a lot of sums, but I also want to sum these functions in a subsequent column&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select
sum(fee1,fee2,fee3) as Fee123,
sum(fee4,fee5,fee6) as Fee456,&lt;BR /&gt;sum(Fee123, Fee456) as TotalSUM
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I know that TotalSUM will not work and the only way to do this is the query below or I can put this in a table and then sum Fee123 + Fee456&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;
sum(sum(fee1,fee2,fee3), sum(fee4,fee5,fee6)) as TotalSUM&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but is there a way to do this cleanly and easily (either procsql or datastep)?&amp;nbsp; My query has a lot of aggregates of aggregates and I want it to simplify this and also avoid creating a bunch of temp tables to make it work.&lt;/P&gt;</description>
    <pubDate>Tue, 24 Apr 2018 18:17:51 GMT</pubDate>
    <dc:creator>mrdlau</dc:creator>
    <dc:date>2018-04-24T18:17:51Z</dc:date>
    <item>
      <title>summing my sums in proc sql easily</title>
      <link>https://communities.sas.com/t5/SAS-Programming/summing-my-sums-in-proc-sql-easily/m-p/457003#M115836</link>
      <description>&lt;P&gt;suppose I have a query that is has a lot of sums, but I also want to sum these functions in a subsequent column&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select
sum(fee1,fee2,fee3) as Fee123,
sum(fee4,fee5,fee6) as Fee456,&lt;BR /&gt;sum(Fee123, Fee456) as TotalSUM
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I know that TotalSUM will not work and the only way to do this is the query below or I can put this in a table and then sum Fee123 + Fee456&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;
sum(sum(fee1,fee2,fee3), sum(fee4,fee5,fee6)) as TotalSUM&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but is there a way to do this cleanly and easily (either procsql or datastep)?&amp;nbsp; My query has a lot of aggregates of aggregates and I want it to simplify this and also avoid creating a bunch of temp tables to make it work.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Apr 2018 18:17:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/summing-my-sums-in-proc-sql-easily/m-p/457003#M115836</guid>
      <dc:creator>mrdlau</dc:creator>
      <dc:date>2018-04-24T18:17:51Z</dc:date>
    </item>
    <item>
      <title>Re: summing my sums in proc sql easily</title>
      <link>https://communities.sas.com/t5/SAS-Programming/summing-my-sums-in-proc-sql-easily/m-p/457009#M115839</link>
      <description>&lt;P&gt;If you want to reference a derived value in the same SQL statement use the CALCULATED keyword.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select
  sum(fee1,fee2,fee3) as Fee123
, sum(fee4,fee5,fee6) as Fee456
, sum(calculated Fee123,calculated  Fee456) as TotalSUM
from ....
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You do realize you are using the SAS function SUM(,) and not the SQL aggregate function SUM() in that query?&lt;/P&gt;
&lt;P&gt;So it is calculating separate sums for each observations. It is similar to if you coded use + operator, but with missing values treated as zero.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  fee1+fee2+fee3 as Fee123
, fee4+fee5+fee6 as Fee456&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Apr 2018 18:23:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/summing-my-sums-in-proc-sql-easily/m-p/457009#M115839</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-04-24T18:23:33Z</dc:date>
    </item>
  </channel>
</rss>

