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;
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.
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.