In proc sql, the summary stats are automatically (re-)merged to the original data, unless you disable this with noremerge option to the proc sql statement, or nosqlremerge system option.
proc sql;
/* test data */
create table one (year num, qtr num, sales num);
insert into one
values (2009, 1, 1000)
values (2009, 2, 1000)
values (2009, 3, 1000)
values (2009, 4, 1000)
values (2010, 1, 1550)
values (2010, 2, 1550)
values (2010, 3, 1550)
values (2010, 4, 1550);
/* attach yearly sum */
create table two as
select year, qtr, sales format=dollar8.
, sum(sales) as total format=dollar8.
from one
group by year
order by year, qtr;
/* check */
select * from two;
/* on lst
year qtr sales total
--------------------------------------
2009 1 $1,000 $4,000
2009 2 $1,000 $4,000
2009 3 $1,000 $4,000
2009 4 $1,000 $4,000
2010 1 $1,550 $6,200
2010 2 $1,550 $6,200
2010 3 $1,550 $6,200
2010 4 $1,550 $6,200
*/
quit;
... View more