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

Hello Everyone! 

 

I am a new SAS user and had a question about Proc Means. 

 

I have the following dataset set.

 

DATA WORK.Trees;
INFILE DATALINES Delimiter = ", ";
INPUT Type $6.
Year
HtFt ;
DATALINES;
Aspen, 2009, 15
Aspen, 2010, 16
Maple, 2010, 6
Maple, 2011, 8
Maple, 2012, 10
Spruce, 2009, 22
Spruce, 2010, 23
Spruce, 2011, 24
Spruce, 2012, 25
;

 

Type = Tree Type

Year = Year of assessment

HtFt = Height of tree in feet

 

Is it possible to use a "Proc Mean" to automatically average the height of each tree for each year, based off of each tree type?

 

I know that I could "Proc Transpose" the data and then average it in a Data Step, but was wondering if there was a way for  Proc Mean to automatically do this.


If you could let me know if this is possible, it would be greatly appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

I'm assuming you want the average of each type of tree over the years. Depending on exactly what you want, you would modify the CLASS statement accordingly. You can get output in multiple manners, in this case, I'm both displaying the output and saving it into two data sets want1, want2 that have different layouts depending on what you're doing next.

 

proc means data=trees Mean /* calculate only mean*/
                                      stackODS  /*controls structure of the want2  output*/
                                       NWAY /*keeps only smallest breakdown, otherwise you get overall as well as grouped summaries*/;

class type; /* which variables you want to group the analysis by*/
var htft; /*variable to analyze*/

*different methods of saving the output to a data set;
output out=want1 mean= /autoname;
ods output summary = want2;

run;

@tagawa_sas wrote:

Hello Everyone! 

 

I am a new SAS user and had a question about Proc Means. 

 

I have the following dataset set.

 

DATA WORK.Trees;
INFILE DATALINES Delimiter = ", ";
INPUT Type $6.
Year
HtFt ;
DATALINES;
Aspen, 2009, 15
Aspen, 2010, 16
Maple, 2010, 6
Maple, 2011, 8
Maple, 2012, 10
Spruce, 2009, 22
Spruce, 2010, 23
Spruce, 2011, 24
Spruce, 2012, 25
;

 

Type = Tree Type

Year = Year of assessment

HtFt = Height of tree in feet

 

Is it possible to use a "Proc Mean" to automatically average the height of each tree for each year, based off of each tree type?

 

I know that I could "Proc Transpose" the data and then average it in a Data Step, but was wondering if there was a way for  Proc Mean to automatically do this.


If you could let me know if this is possible, it would be greatly appreciated!


 

View solution in original post

2 REPLIES 2
Reeza
Super User

I'm assuming you want the average of each type of tree over the years. Depending on exactly what you want, you would modify the CLASS statement accordingly. You can get output in multiple manners, in this case, I'm both displaying the output and saving it into two data sets want1, want2 that have different layouts depending on what you're doing next.

 

proc means data=trees Mean /* calculate only mean*/
                                      stackODS  /*controls structure of the want2  output*/
                                       NWAY /*keeps only smallest breakdown, otherwise you get overall as well as grouped summaries*/;

class type; /* which variables you want to group the analysis by*/
var htft; /*variable to analyze*/

*different methods of saving the output to a data set;
output out=want1 mean= /autoname;
ods output summary = want2;

run;

@tagawa_sas wrote:

Hello Everyone! 

 

I am a new SAS user and had a question about Proc Means. 

 

I have the following dataset set.

 

DATA WORK.Trees;
INFILE DATALINES Delimiter = ", ";
INPUT Type $6.
Year
HtFt ;
DATALINES;
Aspen, 2009, 15
Aspen, 2010, 16
Maple, 2010, 6
Maple, 2011, 8
Maple, 2012, 10
Spruce, 2009, 22
Spruce, 2010, 23
Spruce, 2011, 24
Spruce, 2012, 25
;

 

Type = Tree Type

Year = Year of assessment

HtFt = Height of tree in feet

 

Is it possible to use a "Proc Mean" to automatically average the height of each tree for each year, based off of each tree type?

 

I know that I could "Proc Transpose" the data and then average it in a Data Step, but was wondering if there was a way for  Proc Mean to automatically do this.


If you could let me know if this is possible, it would be greatly appreciated!


 

tagawa_sas
Fluorite | Level 6

Thanks! This is exactly what I was looking for

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 2 replies
  • 665 views
  • 1 like
  • 2 in conversation