<?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: how get grand total from sql in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/how-get-grand-total-from-sql/m-p/30046#M7079</link>
    <description>It seems you want to build a report rather than a table. For that, there many other procs that is more suitable (summary, tabulate, report etc).&lt;BR /&gt;
But, if you want to do it in one sql statement, you could use the above example, and linking the two queries together with a outer union corr:&lt;BR /&gt;
&lt;BR /&gt;
create table sumtable as&lt;BR /&gt;
select product, sum(amt1) as Expr1,sum(amt2) as Expr2&lt;BR /&gt;
from data&lt;BR /&gt;
group by product&lt;BR /&gt;
outer union corr&lt;BR /&gt;
select "Total" as product, sum(amt1) as Expr1, sum(Amt2) as Expr2&lt;BR /&gt;
from data;&lt;BR /&gt;
&lt;BR /&gt;
Whether this is one or two sql statements I think is just a matter of semantics.&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
    <pubDate>Tue, 12 May 2009 15:12:10 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2009-05-12T15:12:10Z</dc:date>
    <item>
      <title>how get grand total from sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-get-grand-total-from-sql/m-p/30043#M7076</link>
      <description>i have data &lt;BR /&gt;
 product   amt1 amt2 &lt;BR /&gt;
    A           10   15&lt;BR /&gt;
    A            20   30&lt;BR /&gt;
    B            15   22&lt;BR /&gt;
    A              5   10&lt;BR /&gt;
   B             8     9&lt;BR /&gt;
&lt;BR /&gt;
proc sql ;&lt;BR /&gt;
create table a as&lt;BR /&gt;
select sum(amt1),sum(amt2)&lt;BR /&gt;
from data&lt;BR /&gt;
group by product;&lt;BR /&gt;
I use sql to sum amt1 and amt2 by product &lt;BR /&gt;
   product   amt1    amt2&lt;BR /&gt;
       A         35         55&lt;BR /&gt;
       B         23         31&lt;BR /&gt;
    total         &lt;BR /&gt;
but don't have the grand total line , how i get it from sql ?&lt;BR /&gt;
total  58 (35+23)  86(55+31)&lt;BR /&gt;
many thanks.</description>
      <pubDate>Mon, 11 May 2009 10:03:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-get-grand-total-from-sql/m-p/30043#M7076</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-05-11T10:03:55Z</dc:date>
    </item>
    <item>
      <title>Re: how get grand total from sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-get-grand-total-from-sql/m-p/30044#M7077</link>
      <description>Is this u want...if so..take..&lt;BR /&gt;
&lt;BR /&gt;
//create sum using your query but slight change as expr1 &amp;amp; 2 &lt;BR /&gt;
create table sumtable as&lt;BR /&gt;
select sum(amt1)AS Expr1,sum(amt2) As  Expr2&lt;BR /&gt;
from data&lt;BR /&gt;
group by product;&lt;BR /&gt;
&lt;BR /&gt;
// expr1 &amp;amp; 2  sum up..&lt;BR /&gt;
&lt;BR /&gt;
select sum(Expr1) ,sum( Expr2)  from data;&lt;BR /&gt;
&lt;BR /&gt;
any Issues..plz tell..&lt;BR /&gt;
thanks &amp;amp; regards,&lt;BR /&gt;
giri</description>
      <pubDate>Mon, 11 May 2009 10:47:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-get-grand-total-from-sql/m-p/30044#M7077</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-05-11T10:47:46Z</dc:date>
    </item>
    <item>
      <title>Re: how get grand total from sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-get-grand-total-from-sql/m-p/30045#M7078</link>
      <description>thanks giri2help, it is not exactly i want&lt;BR /&gt;
&lt;BR /&gt;
       i want to have grand total  with only one proc sql&lt;BR /&gt;
&lt;BR /&gt;
proc sql &lt;BR /&gt;
create table a as&lt;BR /&gt;
select product,sum(amt1),sum(amt2)&lt;BR /&gt;
from data group by product;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
the result from above sql is only&lt;BR /&gt;
output &lt;BR /&gt;
A      35  55&lt;BR /&gt;
B      23  32&lt;BR /&gt;
 but i want the below output  from use one proc sql only.&lt;BR /&gt;
data :&lt;BR /&gt;
product amt1 amt2 &lt;BR /&gt;
A 10 15&lt;BR /&gt;
A 20 30&lt;BR /&gt;
B 15 22&lt;BR /&gt;
A 5 10&lt;BR /&gt;
B 8 9&lt;BR /&gt;
&lt;BR /&gt;
output &lt;BR /&gt;
A      35  55&lt;BR /&gt;
B      23  32&lt;BR /&gt;
total 58   87&lt;BR /&gt;
&lt;BR /&gt;
thanks</description>
      <pubDate>Tue, 12 May 2009 03:42:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-get-grand-total-from-sql/m-p/30045#M7078</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-05-12T03:42:12Z</dc:date>
    </item>
    <item>
      <title>Re: how get grand total from sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-get-grand-total-from-sql/m-p/30046#M7079</link>
      <description>It seems you want to build a report rather than a table. For that, there many other procs that is more suitable (summary, tabulate, report etc).&lt;BR /&gt;
But, if you want to do it in one sql statement, you could use the above example, and linking the two queries together with a outer union corr:&lt;BR /&gt;
&lt;BR /&gt;
create table sumtable as&lt;BR /&gt;
select product, sum(amt1) as Expr1,sum(amt2) as Expr2&lt;BR /&gt;
from data&lt;BR /&gt;
group by product&lt;BR /&gt;
outer union corr&lt;BR /&gt;
select "Total" as product, sum(amt1) as Expr1, sum(Amt2) as Expr2&lt;BR /&gt;
from data;&lt;BR /&gt;
&lt;BR /&gt;
Whether this is one or two sql statements I think is just a matter of semantics.&lt;BR /&gt;
&lt;BR /&gt;
/Linus</description>
      <pubDate>Tue, 12 May 2009 15:12:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-get-grand-total-from-sql/m-p/30046#M7079</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2009-05-12T15:12:10Z</dc:date>
    </item>
  </channel>
</rss>

