🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 01-24-2020 04:06 PM
(2230 views)
Hi SAS master,
I have a dataset like below.
ID | Year | Var1 |
1 | 2001 | 3.5 |
1 | 2003 | 32.6 |
1 | 2005 | 0 |
1 | 2005 | 0 |
1 | 2005 | 5.6 |
1 | 2006 | 72.5 |
1 | 2010 | 0 |
1 | 2012 | 4.5 |
2 | 2004 | 0 |
2 | 2004 | 5 |
2 | 2007 | 42.31 |
2 | 2012 | 95.12 |
2 | 2012 | 86.4 |
2 | 2012 | 49.3 |
2 | 2015 | 0 |
2 | 2015 | 0 |
I would like to get the average for each firm in each year. The dataset I want is below.
ID | Year | Var1 |
1 | 2001 | 3.5 |
1 | 2003 | 32.6 |
1 | 2005 | 1.866667 |
1 | 2006 | 72.5 |
1 | 2010 | 0 |
1 | 2012 | 4.5 |
2 | 2004 | 2.5 |
2 | 2007 | 42.31 |
2 | 2012 | 76.94 |
2 | 2015 | 0 |
what program do I need to use? Thanks.
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
proc summary data=have nway;
class id year;
var var1;
output out=want(drop=_:) mean=;
run;
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
proc sql;
create table want as
select id, year,avg(var1) as avg
from have
group by id,year;
quit;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
proc summary data=have nway;
class id year;
var var1;
output out=want(drop=_:) mean=;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.