BookmarkSubscribeRSS Feed
deleted_user
Not applicable
i have data
product amt1 amt2
A 10 15
A 20 30
B 15 22
A 5 10
B 8 9

proc sql ;
create table a as
select sum(amt1),sum(amt2)
from data
group by product;
I use sql to sum amt1 and amt2 by product
product amt1 amt2
A 35 55
B 23 31
total
but don't have the grand total line , how i get it from sql ?
total 58 (35+23) 86(55+31)
many thanks.
3 REPLIES 3
deleted_user
Not applicable
Is this u want...if so..take..

//create sum using your query but slight change as expr1 & 2
create table sumtable as
select sum(amt1)AS Expr1,sum(amt2) As Expr2
from data
group by product;

// expr1 & 2 sum up..

select sum(Expr1) ,sum( Expr2) from data;

any Issues..plz tell..
thanks & regards,
giri
deleted_user
Not applicable
thanks giri2help, it is not exactly i want

i want to have grand total with only one proc sql

proc sql
create table a as
select product,sum(amt1),sum(amt2)
from data group by product;
quit;

the result from above sql is only
output
A 35 55
B 23 32
but i want the below output from use one proc sql only.
data :
product amt1 amt2
A 10 15
A 20 30
B 15 22
A 5 10
B 8 9

output
A 35 55
B 23 32
total 58 87

thanks
LinusH
Tourmaline | Level 20
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).
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:

create table sumtable as
select product, sum(amt1) as Expr1,sum(amt2) as Expr2
from data
group by product
outer union corr
select "Total" as product, sum(amt1) as Expr1, sum(Amt2) as Expr2
from data;

Whether this is one or two sql statements I think is just a matter of semantics.

/Linus
Data never sleeps

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1163 views
  • 0 likes
  • 2 in conversation