## Proc Means (keyword "Mean")

Occasional Contributor
Posts: 8

# Proc Means (keyword "Mean")

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,

Super User
Posts: 8,125

## Re: Proc Means (keyword "Mean")

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```
Occasional Contributor
Posts: 8

## Re: Proc Means (keyword "Mean")

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.

Super User
Posts: 23,774

## Re: Proc Means (keyword "Mean")

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;

Super User
Posts: 13,583

## Re: Proc Means (keyword "Mean")

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.

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.

Super User
Posts: 23,774

## Re: Proc Means (keyword "Mean")

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;``````
Super User
Posts: 13,583