Help using Base SAS procedures

Weighting using Proc Means

Accepted Solution Solved
Reply
Occasional Contributor KJC
Occasional Contributor
Posts: 9
Accepted Solution

Weighting using Proc Means

I am trying to make sure I correctly use weights when I calculate proc means.

I am trying to take a mean of several observations. Some of the observations come from data that had more individuals contributing, therefore I consider that observation to be more precise compared to the observations that fewer individuals contributed to. I am trying to take the mean where the observations with the higher number of people are weighted more heavily compared to observations that have fewer people.

Here is a snapshot of the data:

n     var1

14     0.80      

14     0.78

14     0.81

13     0.85

11     0.87

10     0.88

9      0.90

8      0.91

I would like to take the mean of var1 and give more weight to the observations with a higher value for n.

Thanks!


Accepted Solutions
Solution
‎03-20-2014 04:14 PM
Super User
Posts: 11,343

Re: Weighting using Proc Means

Have you tried running proc means on the data once with Freq  n; and once with Weight n; and without either? You'll see the values for mean and std deviation change.

proc means data = have;

     var var1;

     weight n;

     title "With weight";

run;

proc means data = have;

     var var1;

     freq n;

     title "With Freq";

run;

proc means data = have;

     var var1;

     Title "With neither Freq nor weight";

run;title;

View solution in original post


All Replies
Respected Advisor
Posts: 3,799

Re: Weighting using Proc Means

Can you just use the FREQ statement to tell PROC MEANS the N for each value?

Occasional Contributor KJC
Occasional Contributor
Posts: 9

Re: Weighting using Proc Means

Posted in reply to data_null__

data_null_, I'm not sure what you mean. Can you provide an example?

Super User
Posts: 19,855

Re: Weighting using Proc Means

Have you looked into the weight statement?

Base SAS(R) 9.2 Procedures Guide

Occasional Contributor KJC
Occasional Contributor
Posts: 9

Re: Weighting using Proc Means

Yes, I am just trying to make sure I use the weight statement correctly. I don't understand how to properly use the weight statement and the vardiff option.

Trusted Advisor
Posts: 1,932

Re: Weighting using Proc Means

KJC, the SAS documentation has examples on how to use the WEIGHT statement to compute weighted means. Is that not a good enough explanation for you?

The VARDEF option (not vardiff) is irrelevant for computing means.

Occasional Contributor KJC
Occasional Contributor
Posts: 9

Re: Weighting using Proc Means

Posted in reply to PaigeMiller

PaigeMiller, I read the explanation but I guess I need a little more clarification.

When using the weight statement, how do I know that the thing being weighted more heavily is the larger value of n rather than something else?

I bring up VARDEF (excuse the mistype) because there are several different options for that and I want to make sure to use the most appropriate one given that the website says this

"When you use the WEIGHT statement, consider which value of the VARDEF= option is appropriate. See the discussion of VARDEF= and the calculation of weighted statistics in Keywords and Formulas for more information. "


I also plan to compute the confidence interval for each mean and I believe I need to include the VARDEF option in order to do that.

Trusted Advisor
Posts: 1,932

Re: Weighting using Proc Means

When using the weight statement, how do I know that the thing being weighted more heavily is the larger value of n rather than something else?

Because the SAS documentation provides the actual formulas being used

I bring up VARDEF (excuse the mistype) because there are several different options for that and I want to make sure to use the most appropriate one given that the website says this

"When you use the WEIGHT statement, consider which value of the VARDEF= option is appropriate. See the discussion of VARDEF= and the calculation of weighted statistics in Keywords and Formulas for more information. "


I also plan to compute the confidence interval for each mean and I believe I need to include the VARDEF option in order to do that.

Ah, new information ... you're not just computing the mean, you are going to compute the variance or standard deviation. In that case, either VARDEF=WDF or VARDEF=WEIGHT would be appropriate, but without you explaining more about the data and what you are trying to do, I cannot advise you further.

Super User
Posts: 19,855

Re: Weighting using Proc Means

Posted in reply to PaigeMiller

Also look into proc surveymeans.

Super User
Posts: 11,343

Re: Weighting using Proc Means

If your N variable reflects a count of original observations with the value of Var1 you likely actually want to use FREQ N; instead of WEIGHT N;

The Freq option replicates the original data distribution for Var1. The second option in loosely analogous to placing weights with a value of N on a ruler at points with the value of Var1 and determining the mean (balance point). Variances and standard deviations will be significantly difference due to the number of values used in the calculations. With Weight the number of points will be 8, with Freq over 90.

Occasional Contributor KJC
Occasional Contributor
Posts: 9

Re: Weighting using Proc Means

Ballardw, could you give me some example code describing what you are talking about?

The value "n" is referring to the number of individuals from my sample contributing to the value for "var1".

Solution
‎03-20-2014 04:14 PM
Super User
Posts: 11,343

Re: Weighting using Proc Means

Have you tried running proc means on the data once with Freq  n; and once with Weight n; and without either? You'll see the values for mean and std deviation change.

proc means data = have;

     var var1;

     weight n;

     title "With weight";

run;

proc means data = have;

     var var1;

     freq n;

     title "With Freq";

run;

proc means data = have;

     var var1;

     Title "With neither Freq nor weight";

run;title;

Occasional Contributor KJC
Occasional Contributor
Posts: 9

Re: Weighting using Proc Means

thank you!

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 12 replies
  • 396 views
  • 7 likes
  • 5 in conversation