Dear all,
For variable X, I try to calculate min, max and mean with one statement in PROC TABULATE.
Min and max is no problem.
For mean however, I need a weighted average.
This is the sum of variable X, divided not by n, but with the sum of the weight variable Y.
How can this be done (not with data step programming or proc report stuff)?
I tried several options without success (weight statement, DF option, ...)
GreetZ,
Herman
I think you may misunderstand the effect of a weight statement as I believe that it always affects the numerator. You can use vardef to determine the effect on the denominator. Take a look at:
http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473744.htm
I think you may misunderstand the effect of a weight statement as I believe that it always affects the numerator. You can use vardef to determine the effect on the denominator. Take a look at:
http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473744.htm
As far as I know ,It looks like proc tabulate can not calculate weighted mean.Maybe you should use data step or SQL to get it.
Ksharp
Ksharp,
Why do you say that? Try the following:
data test;
set sashelp.class;
if sex eq "F" then impact=2;
else impact=1;
run;
PROC TABULATE data=test;
CLASS sex;
VAR height;
TABLE height*MEAN, sex ALL;
RUN;
PROC TABULATE data=test;
CLASS sex;
VAR height;
weight impact;
TABLE height*MEAN, sex ALL;
RUN;
Art. You are right. I overlooked it.
You can also do weighted averages in PROC MEANS and PROC REPORT. This may be useful if you wish to confirm the calculations by another independent method.
I agree with verifying the results, but I think what the OP originally indicated wanting was something like:
data test;
set sashelp.class;
if sex eq "F" then impact=2;
else impact=1;
new_height=height/impact;
run;
PROC TABULATE data=test;
CLASS sex;
VAR new_height;
weight impact;
TABLE new_height*MEAN, sex ALL;
RUN;
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.