<?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: Sql summing in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sql-summing/m-p/920312#M362462</link>
    <description>Thank you, Patrick,&lt;BR /&gt;How could I have the total value in column (not just in the last line), please ?</description>
    <pubDate>Thu, 14 Mar 2024 16:51:11 GMT</pubDate>
    <dc:creator>SASdevAnneMarie</dc:creator>
    <dc:date>2024-03-14T16:51:11Z</dc:date>
    <item>
      <title>Sql summing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sql-summing/m-p/920183#M362415</link>
      <description>Hello Experts,&lt;BR /&gt;&lt;BR /&gt;I would like to calculate sum (Quantity) by Id (group by Id) and the sum(Quantity) as total, but I don’t know how to do it in the same proc sql statement.&lt;BR /&gt;&lt;BR /&gt;Thank you for your help!</description>
      <pubDate>Wed, 13 Mar 2024 19:25:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sql-summing/m-p/920183#M362415</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2024-03-13T19:25:40Z</dc:date>
    </item>
    <item>
      <title>Re: Sql summing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sql-summing/m-p/920188#M362417</link>
      <description>&lt;P&gt;I always prefer doing this in PROC SUMMARY.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SUMMARY data = have;
var quantity.
class id;
output out=want sum=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The row in WANT with _type_=0 is the overall total&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2024 19:37:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sql-summing/m-p/920188#M362417</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-03-13T19:37:42Z</dc:date>
    </item>
    <item>
      <title>Re: Sql summing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sql-summing/m-p/920189#M362418</link>
      <description>&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
	select type, sum(msrp) as sum
	from sashelp.cars
	group by type
	outer union corr
	select 
	"ALL" as type, sum(msrp) as sum
	from sashelp.cars;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;To do it in one statement you’d need to use the union set operator.&lt;BR /&gt;&lt;BR /&gt;First with the group by, and then without&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2024 19:49:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sql-summing/m-p/920189#M362418</guid>
      <dc:creator>Mazi</dc:creator>
      <dc:date>2024-03-13T19:49:38Z</dc:date>
    </item>
    <item>
      <title>Re: Sql summing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sql-summing/m-p/920228#M362433</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/286185"&gt;@SASdevAnneMarie&lt;/a&gt;&amp;nbsp;As demonstrated Proc Summary can do this in one go and though will likely perform better.&lt;/P&gt;
&lt;P&gt;Below the coding approach using a SQL SET operator as documented &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/sqlproc/n0vo2lglyrnexwn14emi8m0jqvrj.htm#n05ape0l2g4a37n1mq4w24mjm5li" target="_self"&gt;here&lt;/A&gt;. Important is to also use the ALL keyword so the SQL doesn't try to dedup the result.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	select type, sum(msrp) as sum
	from sashelp.cars
	group by type
	union corr ALL
	select 
	"ALL" as type, sum(msrp) as sum
	from sashelp.cars;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2024 02:22:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sql-summing/m-p/920228#M362433</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-03-14T02:22:55Z</dc:date>
    </item>
    <item>
      <title>Re: Sql summing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sql-summing/m-p/920312#M362462</link>
      <description>Thank you, Patrick,&lt;BR /&gt;How could I have the total value in column (not just in the last line), please ?</description>
      <pubDate>Thu, 14 Mar 2024 16:51:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sql-summing/m-p/920312#M362462</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2024-03-14T16:51:11Z</dc:date>
    </item>
    <item>
      <title>Re: Sql summing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sql-summing/m-p/920331#M362468</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/286185"&gt;@SASdevAnneMarie&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you, Patrick,&lt;BR /&gt;How could I have the total value in column (not just in the last line), please ?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That starts sounding more like a report.&lt;/P&gt;
&lt;P&gt;Perhaps time to share some example data and the expected result for that data.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2024 17:53:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sql-summing/m-p/920331#M362468</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-03-14T17:53:23Z</dc:date>
    </item>
    <item>
      <title>Re: Sql summing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sql-summing/m-p/920334#M362471</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/286185"&gt;@SASdevAnneMarie&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you, Patrick,&lt;BR /&gt;How could I have the total value in column (not just in the last line), please ?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It's always a good idea to tell us -- or even better, show us -- what you want, in your first post in the thread. You should do that from now on. You will get faster and better answers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SUMMARY data = have;
var quantity.
class id;
output out=want sum=;
run;

data want2;
    if _n_=1 then set want(where=(_type_=0) rename=(quantity=total));
    set want(where=(_type_=1));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2024 18:43:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sql-summing/m-p/920334#M362471</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-03-14T18:43:21Z</dc:date>
    </item>
    <item>
      <title>Re: Sql summing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sql-summing/m-p/920353#M362478</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/286185"&gt;@SASdevAnneMarie&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you, Patrick,&lt;BR /&gt;How could I have the total value in column (not just in the last line), please ?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;SQL is likely no more the ideal syntax for this requirement - but here you go.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  select type, group_sum, sum(group_sum) as grand_total
  from
    (
    	select type, sum(msrp) as group_sum
    	from sashelp.cars
    	group by type
    )
	union corr ALL
	select 
	"ALL" as type, sum(msrp) as group_sum, sum(msrp) as grand_total
	from sashelp.cars;
    ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Mar 2024 22:50:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sql-summing/m-p/920353#M362478</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-03-14T22:50:17Z</dc:date>
    </item>
    <item>
      <title>Re: Sql summing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sql-summing/m-p/920379#M362493</link>
      <description>&lt;P&gt;Don't do reports with SQL. SAS provides much better tools (REPORT, SUMMARY, TABULATE) for this.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 07:17:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sql-summing/m-p/920379#M362493</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-03-15T07:17:19Z</dc:date>
    </item>
  </channel>
</rss>

