I have a dataset with Year in the rows, and the months Sep-May as the columns. I am trying to sum the months by year, in this case Sep-May is considered one year. I am unsure of how to go about this as I cannot figure out how to sum all 9 months together for about 200 years.
Here is what I've been working with though I have been unsuccessful.
proc means data=schoolyear sum maxdec=0;
class year;
var Sep Oct Nov Dec Jan Feb Mar Apr May;
run;
Thank you in advance!
If you're summing within a single row, then you would use the SUM function.
data want;
set schoolyear;
annual_total = sum(sep, oct, nov, ... , may); *if the variables are NOT side by side you have to list them all;
annual_total2 = sum(of sep--may); *if the variables are side by side;
run;
@emkotnik wrote:
I have a dataset with Year in the rows, and the months Sep-May as the columns. I am trying to sum the months by year, in this case Sep-May is considered one year. I am unsure of how to go about this as I cannot figure out how to sum all 9 months together for about 200 years.
Here is what I've been working with though I have been unsuccessful.
proc means data=schoolyear sum maxdec=0;
class year;
var Sep Oct Nov Dec Jan Feb Mar Apr May;
run;
Thank you in advance!
I would sum up in a slightly different order. First, begin with the program you have, but put the results into an output data set:
proc means data=schoolyear noprint nway;
class year;
var Sep Oct Nov Dec Jan Feb Mar Apr May;
output out=monthly_totals (drop=_type_ _freq_) sum=;
run;
This gives you a SAS data set with the same 10 variables you started with, but the month variables all contain the SUM of their original values. In other words, you have a much smaller data set: 200 observations (one for each year) and the same 10 variables. If you want to add them up, it's easy:
data want;
set monthly_totals;
yearly_total = Sep + Oct + Nov + Dec + Jan + Feb + Mar + Apr + May;
run;
The advantage of doing the steps in this order occurs when you start with a lot of observations. You don't need to add up the 9 monthly values for every observation ... just add their totals that come out of PROC MEANS.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.