Date: Fri, 20 May 2011 08:46:46 -0500
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: PROC MEANS/WEIGHTS - any way to output normalised weight
values?
In-Reply-To: <201105200229.p4JM5sZA000503@waikiki.cc.uga.edu>
Content-Type: text/plain; charset="US-ASCII"
I wouldn't say wrong, for it is another, perhaps more efficient solution
to get the weights in a vector that sum to one, if that is the main
objective. However, even though the weighted mean will stay the same with
either the original or normalized weights, the variance, standard dev, and
standard error will not be the same (contrary to what I might had alluded
to before), e.g., with the sample dataset, using the unnormalized weights
proc means data=tst mean var stderr std;
var value;
weight wn2;
run;
Mean Variance Std Error Std Dev
------------------------------------------------------------
7.8461150 14.5034851 1.4712917 3.8083441
embellishing the GLIMMIX solution a bit gives:
ods output parameterestimates=prms;
ods listing close;
proc glimmix data=tst;
wgt = wn2 / &sumwgt. ; * enter a programming statement;
model value = / solution;
weight wn2;
ID wgt value; * enter normalized weight and original value as ID
variables;
OUTPUT out=prd predicted=phat ;
run;
ods listing;
data prms; SET prms;
if _n_ = 2 then std = sqrt(estimate);
proc print NOObs; run;
Effect Estimate StdErr DF tValue Probt std
Intercept ** 7.8461 **1.4713 5 5.33 0.0031 .
Scale **14.5035 9.1728 . . . 3.80834 **
note the four weighted components estimated from PROC MEANS with the
original weights are produced directly from the solution option and a
SQRT() and the normalized weights are produced as an ID var in the output
dataset.
wherease the "slick" way to find normalized weights and then estimate
weighted stats changes the estimates of the var, stderr, and std:
PROC STDIZE ... ;
proc means data=data1 mean var std stderr;
var value;
weight wn2;
run;
Mean Variance Std Dev Std Error
------------------------------------------------------------
7.8461150 2.1646993 1.4712917 1.4712917
In other words, with GLIMMIX you can estimate the weighted means, std dev,
var, ... etc. with the original weights AND at the same time output the
weights on a "normalized" scale that to some extent indicates the percent
or proportion of the value of each observation that is more easily
understood than the original weights.
Using GLIMMIX to only estimate a weighted mean is a bit like calling out
the elite Navy Seals to rescue Fluffy stuck in a tree-top, but does show
another aspect of its versatility.
Robin High
UNMC
From:
oloolo <dynamicpanel@YAHOO.COM>
To:
SAS-L@LISTSERV.UGA.EDU
Date:
05/19/2011 09:30 PM
Subject:
Re: PROC MEANS/WEIGHTS - any way to output normalised weight values?
Sent by:
"SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
since it still has to pass the data twice, I think using PROC STDIZE
serves
better :
proc stdize data=data0 method=sum out=data1;
var weight;
run;
proc means data=data1....
....
run;
correct me if I am wrong
On Thu, 19 May 2011 10:47:32 -0500, Robin R High <rhigh@UNMC.EDU> wrote:
>Andrew,
>
>GLIMMIX has a way you can retrieve the normalized weight values when
>computing weighted means for any set of positive weight values. You
would
>need to compute the sum of the weights externally, and then with a
>programming statement and an ID variable enter them into the output data
>file to retrieve the individual weights that sum to 1.
>
>DATA tst;
>input wn1 value;
>wn2 = wn1*6.7;
>cards;
>0.19853 10.8
>0.15686 10.3
>0.20343 7.6
>0.18627 1.5
>0.13481 10.0
>0.12010 7.6
>;
>
>proc print; run;
>
>proc means data=tst mean stderr;
>var value;
>weight wn2;
>run;
>
>proc means data=tst noprint;
>var wn1 wn2;
>output out=sm(keep=sumw: ) sum=sumw1 sumw2;
>
>proc print; run;
>
>
>* put the sum of the weights into a macro variable;
>DATA _null_; SET sm; CALL SYMPUTX("sumwgt",sumw2);
>RUN;
>
>%PUT &sumwgt. ;
>
>ods select parameterestimates;
>
>proc glimmix data=tst;
>wgt = wn2 / &sumwgt. ; * enter a programming statement;
>model value = / solution;
>weight wn2;
>ID wgt; * enter normalized weight as an ID variable;
>OUTPUT out=prd predicted=phat ;
>run;
>
>* add in the response variable;
>DATA prd; SET prd; SET tst(keep=value);
>
>proc print data=prd; run;
>
>* new variable wgt sums to 1 and matches the original vector of weights;
>
>proc means data=prd sum; var wgt; run;
>
>
>
>Robin High
>UNMC
>
>
>
>
>
>From:
>"Clapson, Andrew - PPD/DPP" <Andrew.Clapson@STATCAN.GC.CA>
>To:
>SAS-L@LISTSERV.UGA.EDU
>Date:
>05/19/2011 08:40 AM
>Subject:
>Re: PROC MEANS/WEIGHTS - any way to output normalised weight values?
>Sent by:
>"SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
>
>
>
>Hey Art, Robin,
>
>Actually, I do need the weights separated, even when they are non-unique
>- 'collapsing' them into their respective sums would work for the
>purposes of that calculation, but actually wouldn't suit my purposes.
>
>I want the individual, normalised weights. Although, of course the
>actual mean is also important. : )
>I was just looking for a shortcut here...
>
>
>Andy
>
>-----Original Message-----
>From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
>Arthur Tabachneck
>Sent: May-18-11 6:04 PM
>To: SAS-L@LISTSERV.UGA.EDU
>Subject: Re: PROC MEANS/WEIGHTS - any way to output normalised weight
>values?
>
>Robin,
>
>I'm not sure what you are questioning, although I obviously may have
>misunderstood what Andrew was asking for. A weighted mean is simply the
>sum
>of the products (given your example the sum of the wn*value variables),
>divided by the sum of the weighting variable (in your example the sum of
>wn).
>
>As shown below, I think, the same analyses on tst2 provide the same
>result.
>Am I missing something here?
>
>Art
>
>DATA tst;
>input wn value;
>cards;
>8.1 10.8
>6.4 10.3
>8.3 7.6
>7.6 1.5
>5.5 10.0
>4.9 7.6
>;
>
>DATA tst2;
>input wn value;
>cards;
>8.1 10.8
>6.4 10.3
>13.2 7.6
>7.6 1.5
>5.5 10.0
>;
>
>proc means data=tst mean;
> var value;
> weight wn;
>run;
>
>proc means data=tst2 mean;
> var value;
> weight wn;
>run;
>
>proc freq data=tst order=data;
>tables value / nocum;
>weight wn;
>run;
>
>proc freq data=tst2 order=data;
>tables value / nocum;
>weight wn;
>run;
>
>-----Original Message-----
>From: Robin R High [mailto:rhigh@unmc.edu]
>Sent: Wednesday, May 18, 2011 5:31 PM
>To: Arthur Tabachneck
>Cc: SAS-L@LISTSERV.UGA.EDU
>Subject: Re: PROC MEANS/WEIGHTS - any way to output normalised weight
>values?
>
>Art,
>
>It produces the weights as Andrew described them if the variable cost is
>unique; however, given repeats in the value of interest:
>
>
>DATA tst;
>input wn value;
>cards;
>8.1 10.8
>6.4 10.3
>8.3 7.6
>7.6 1.5
>5.5 10.0
>4.9 7.6
>;
>
>proc freq order=data;
>tables value / nocum;
>weight wn;
>run;
>
>value Frequency Percent
>------------------------------
> 10.8 8.1 19.85
> 10.3 6.4 15.69
> 7.6 13.2 32.35 **
> 1.5 7.6 18.63
> 10 5.5 13.48
>
>** Frequency is the sum of 8.3+4.9 since two observations have the value
>7.6
>
>Robin High
>UNMC
>
>
>
>
>
>
>From:
>Arthur Tabachneck <art297@ROGERS.COM>
>To:
>SAS-L@LISTSERV.UGA.EDU
>Date:
>05/17/2011 04:38 PM
>Subject:
>Re: PROC MEANS/WEIGHTS - any way to output normalised weight values?
>Sent by:
>"SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
>
>
>
>Andrew,
>
>Does the following provide what you are looking for?
>
>proc means data=have mean;
> var cost;
> weight weight_number;
>run;
>
>proc freq data=have;
> tables cost;
> weight weight_number;
>run;
>
>HTH,
>Art
>-------
>On Tue, 17 May 2011 16:45:28 -0400, Clapson, Andrew - PPD/DPP
><Andrew.Clapson@STATCAN.GC.CA> wrote:
>
>>Sorry...I wasn't being very clear. Maybe the request itself actually
>>doesn't even make much sense, haha. : )
>>
>>Anyway, what I meant was, let's say I'm calculating a weighted average
>>of three prices:
>>$10, $15, $20.
>>
>>These numbers have weights (measured in some arbitrary unit),
>>respectively, of let's say:
>>50, 100, 50.
>>
>>What I was curious about was if it would be possible to get an output
>>dataset (as an out from the PROC MEANS procedure) containing the
>>normalised weights - i.e. in a percentage or decimal form, in this
>case;
>>0.25, 0.5, 0.25,
>>
>>for instance.
>>
>>
>>Hope that clears things up...someday I'll learn my lesson about
>>ambiguous postings....
>>Thanks
>>
>>Andy
>>
>>
>>-----Original Message-----
>>From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
>>Data _null_;
>>Sent: May-17-11 3:49 PM
>>To: SAS-L@LISTSERV.UGA.EDU
>>Subject: Re: PROC MEANS/WEIGHTS - any way to output normalised weight
>>values?
>>
>>Ok I'll bite.
>>
>>I don't know what you are asking for. I googled briefly but found
>>nothing that seems to fit your question.
>>
>>Can you explain in more detail for this dumb hillbilly. Especially
>>the trivial part.
>>
>>
>>
>>On Tue, May 17, 2011 at 9:40 AM, Clapson, Andrew - PPD/DPP
>><Andrew.Clapson@statcan.gc.ca> wrote:
>>> Hey all,
>>>
>>> Just curious if it is at all possible to get an output dataset of
>>> weights used in a Weights statement?
>>>
>>> Let's say, for example, for weight variables used in calculated a
>>> weighted mean via the PROC MEANS procedure. While I doubt that SAS
>>> explicitly calculates individual normalised weights, is there perhaps
>>> some functionality to extract the weights in this form? (Yes, I
>>realise
>>> the calculation is trivial, but if SAS can do it within the PROC
>MEANS
>>> procedure, it will save me a step.)
>>>
>>> Thanks for the help,
>>>
>>> Andy Clapson
>>>
|