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
- /
- SAS Programming
- /
- General Programming
- /
- Proc Means (keyword "Mean")

Topic Options

- Subscribe to 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
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-02-2016 01:23 PM

Hello,

Is there a way to manipulate the variables in the mean calculation? Example: by default it is currently dividing the "SUM" by "N"(non missing values). Instead I would like it to divide "SUM" by "N Obs" (number of observations). Is there any way to do this?

PROC MEANS DATA= WAH_vs_InHouse N sum max mean maxdec=2;

where (month = 5 or month = 6);

CLASS PCF month Location;

var hours_mtd;

Thank You,

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

09-02-2016 01:57 PM

No.

Either convert your missing values to zeros before call PROC MEANS.

Or take the output from PROC MEANS and "correct" it yourself.

```
data class ;
set sashelp.class ;
age2=age;
if _n_=3 then age2=.;
age3=age;
if _n_=3 then age3=0;
run;
proc summary data=class ;
var age: ;
output out=stats N= MEAN= SUM= / autoname;
run;
data want ;
set stats ;
age2_mean_corrected = age2_sum / _freq_ ;
put (_freq_ age2_: age3_mean ) (=/);
run;
```

This yeidls:

_FREQ_=19 age2_N=18 age2_Mean=13.333333333 age2_Sum=240 age2_mean_corrected=12.631578947 age3_Mean=12.631578947

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

09-02-2016 03:16 PM

I just notices the zeros are already there in my Data Set. The N column just doesn't recognize them as non-missing values. It considers a numeric zero to be missing as well. Wonder why that is, when a "." actually represents zero. So the mean is completely ignoring zeros.

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

09-02-2016 03:19 PM

You probably have either a format that displays it this way or the missing option is set to show a 0. Either way, proc means is using the underlying values.

Reset missing option:

option missing=.;

Remove format:

format var;

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

09-02-2016 03:25 PM

Teazelado wrote:

SAS MISSING does **not** mean 0. It is not used in any calculations.

Setting the Missing option to display '0' does not mean that there is any value there. The display character is for human convenience not calculation.

Rerun your proc means after this statment:

options missing='A';

and see if you get any difference. Likely not.

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

09-02-2016 02:19 PM

I don't think so. Depending on your requirements, output dataset or report, you could consider proc report and/or a custom data step or SQL.

```
proc sql;
create table summary as
select pcf, month, location, count(*), sum(hours_mtd) as total_hours, max(hours_mtd) as max_hours, sum(hours_mtd)/count(*),
from wah_vs_inhouse
group by pcf, month, location;
quit;
```

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

09-02-2016 02:56 PM

If this is the only calclulation you could make a temporary data set with the variable hours_mtd set to 0 for the missing values. Just remember that data set may not be appropriate for other uses.