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

Hi SAS master, 

 

I have a dataset like below.

 

IDYearVar1
120013.5
1200332.6
120050
120050
120055.6
1200672.5
120100
120124.5
220040
220045
2200742.31
2201295.12
2201286.4
2201249.3
220150
220150

 

I would like to get the average for each firm in each year. The dataset I want is below.

 

IDYearVar1
120013.5
1200332.6
120051.866667
1200672.5
120100
120124.5
220042.5
2200742.31
2201276.94
220150

 

what program do I need to use? Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
proc summary data=have nway;
class id year;
var var1;
output out=want(drop=_:) mean=;
run;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20
proc sql;
create table want as
select id, year,avg(var1) as avg
from have
group by id,year;
quit;

novinosrin
Tourmaline | Level 20
proc summary data=have nway;
class id year;
var var1;
output out=want(drop=_:) mean=;
run;
ballardw
Super User

I suggest that you also look at the results for @novinosrin's Proc Summary solution without the NWAY option and removing the (drop=) option on the output set.

 

Proc summary can create LOTS of different groups of summaries with a single pass through the data which can be very helpful for some tasks as you may not need to create multiple data sets but just select the appropriate _type_ value.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 3 replies
  • 1904 views
  • 0 likes
  • 3 in conversation