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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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