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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.