Date: Thu, 19 Feb 2009 13:16:02 -0600
Reply-To: Robin R High <rhigh@UNMC.EDU>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Robin R High <rhigh@UNMC.EDU>
Subject: Re: Weighted average problem
In-Reply-To: <148353.73517.qm@web51008.mail.re2.yahoo.com>
Content-Type: text/plain; charset="US-ASCII"
Yes,
I obviously wasn't awake yet or too focussed on other daily tasks (and
thinking more in terms of discrepanices which can result in other summary
stats in TABULATE with the WEIGHT and FREQ statements) when i sent it --
though it may help to remind oneself what is computations are occuring
within a DATA step.
proc tabulate data=one;
var x;
table x, n*f=3.0 mean*f=7.4 var*f=6.3 / rts=8;
freq y;
run;
---------------------------
| | N | Mean | Var |
|------+---+-------+------|
|x | 30| 2.3333| 0.230|
---------------------------
proc tabulate data=one;
var x;
table x, n*f=3.0 mean*f=7.4 var*f=6.3 / rts=11;
weight y;
run;
---------------------------
| | N | Mean | Var |
|------+---+-------+------|
|x | 2| 2.3333| 6.667|
---------------------------
Robin H.
UNMC
Steve Denham <stevedrd@yahoo.com>
02/19/2009 12:32 PM
To
Robin R High <rhigh@UNMC.EDU>, SAS-L@LISTSERV.UGA.EDU
cc
Subject
Re: Weighted average problem
Maybe I'm missing something in the OP, but won't this do it too?
proc means data=one;
var x;
weight y;
run;
Steve Denham
Associate Director, Biostatistics
MPI Research, Inc.
----- Original Message ----
From: Robin R High <rhigh@UNMC.EDU>
To: SAS-L@LISTSERV.UGA.EDU
Sent: Thursday, February 19, 2009 9:44:25 AM
Subject: Re: Weighted average problem
If you want to do it with the individual data values in a single PROC with
a WEIGHT statement, I can't imediately think of a way, though one pass
thru with a DATA step will easily do it:
data one;
input x y;
sumN + x*y;
sumD + y ;
wgt_mean =sumN/sumD;
cards;
2 20
3 10
;
proc print; run;
Robin High
UNMC
chumba <vikas.dharamsattu@GMAIL.COM>
Sent by: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
02/19/2009 06:40 AM
Please respond to
chumba <vikas.dharamsattu@GMAIL.COM>
To
SAS-L@LISTSERV.UGA.EDU
cc
Subject
Weighted average problem
Hi,
I need to fix the code for calculation of weighted mean
X 2 20
Y 3 10
Average = (2*20)+(3*10) / (20+10) instead of (2+3)/2 which the present
SAS code is calculating.
Can I acheive this formula by SAS??
Thanks