BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Jaheuk
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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

View solution in original post

6 REPLIES 6
art297
Opal | Level 21

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

Ksharp
Super User

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

art297
Opal | Level 21

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;

Ksharp
Super User

Art. You are right. I overlooked it.

SASKiwi
PROC Star

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.

art297
Opal | Level 21

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;

sas-innovate-2024.png

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.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 9890 views
  • 2 likes
  • 4 in conversation