BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sundeep_M
Calcite | Level 5

In sashelp there is a file name countseries (FOR SAS UNIVERSITY EDITION) , how can i make jan2004 to dec2004 into one major category as'2004 and add up all the units for 2004 and make a table consisting of only year and total units in that particular year.

Can anyone please explain this with the code.

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16
data countseries;
set sashelp.countseries;
year=year(date);
run;

proc sql;
create table want as select year, sum(units) as sum from countseries group by year;
quit;
Thanks,
Jag

View solution in original post

5 REPLIES 5
Jagadishkatam
Amethyst | Level 16
data countseries;
set sashelp.countseries;
year=year(date);
run;

proc sql;
create table want as select year, sum(units) as sum from countseries group by year;
quit;
Thanks,
Jag
Sundeep_M
Calcite | Level 5

thank you sir

Jagadishkatam
Amethyst | Level 16
Hi Sundeep, If it helped you, could you please mark the this as answered so it helps future users narrow down what responses to look at.
Thanks,
Jag
novinosrin
Tourmaline | Level 20

The solution should be just one pass of sql. 

 

A datastep to compute year and then proc sql for by group is very costly.

 

select clause can be used to compute year

and the computed column can be used as grouping var. 

 

 

Jagadishkatam
Amethyst | Level 16

I agree  with you @novinosrin, the code could simplified in one step proc sql as below

 

proc sql;
create table want as select year(date) as year, sum(units) as sum from sashelp.countseries group by year;
quit;

 

Thanks,
Jag

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 910 views
  • 0 likes
  • 3 in conversation