Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- how get grand total from sql

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-11-2009 06:03 AM

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.

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-11-2009 06:47 AM

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

//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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-11-2009 11:42 PM

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

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-12-2009 11:12 AM

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

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