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!
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!
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!
Thanks! This is exactly what I was looking for
Nearly 200 sessions are now available on demand in the Innovate Hub.
Watch Now →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.