SAS Notes

27 May 2009

Creating Weighted Statistics in SAS

I wanted to use Proc means to calculate weighted statistics but the options seem too involved.

In the specific example, you have hundred days that are zero and the remaining days have positive values where some of the zeros are not coded as zeros but simply the date is omitted. What is the average daily value?If you computed an unweighted simple average, it will be misleading. It will overstate the mean since it will not weight the zeros.

So the observed average needs to be multipled by a proportion of number of non-zero days over total number of days. However the variance cannot be easily adjusted. So in SAS, I created a row of zero and weighted it with 365-number of non zero rows. I created a weight of 1 for every non-zero row. If you use proc means and apply weighting option you are done. The mean is easy......... but weight ooops........ wait!

The variance needs more work. You need to specify a variance deflator option to indicate you really want to use the total of weights to arrive at the variance. This option is VARDEF=WEIGHT.

Leave a Reply