turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- Analytics
- /
- Stat Procs
- /
- Summing Months by year

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-02-2018 09:35 PM - edited 03-02-2018 10:00 PM

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!

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to emkotnik

03-02-2018 09:55 PM - edited 03-02-2018 10:29 PM

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!

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to emkotnik

03-02-2018 10:41 PM - edited 03-02-2018 10:41 PM

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.