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.