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!
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;
Can you just use the FREQ statement to tell PROC MEANS the N for each value?
data_null_, I'm not sure what you mean. Can you provide an example?
Have you looked into the weight statement?
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.
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.
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.
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.
Also look into proc surveymeans.
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.
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".
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;
thank you!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: