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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.