Date: Wed, 27 Feb 2008 16:03:16 0500
ReplyTo: Hari Nath <hari_s_nath@YAHOO.COM>
Sender: "SAS(r) Discussion" <SASL@LISTSERV.UGA.EDU>
From: Hari Nath <hari_s_nath@YAHOO.COM>
Subject: Re: weights in tabulate
Thanks Yu for your correction....the reason i was confused bcos, i got the
weighted means unchanged both in summary and tabulate.....but i could
simulate the weighted sum in both summary and tabulate.....i just added a
weight statement in your third tabulate statement and the means kept
unchanged, as you said the effect is cancelled out.......this was quite
new for me....
thanks again for your answer and for everyone who looked at the problem....
hari.
On Wed, 27 Feb 2008 14:38:21 0600, Yu Zhang <zhangyu05@GMAIL.COM> wrote:
>Hari,
>
>After I send out the message, I kept reading the DOC. *unfortunaltely*
><http://www.google.com/search?
hl=en&sa=X&oi=spell&resnum=0&ct=result&cd=1&q=unfortunaltely+&spell=1>
> I
>missunderstood the formular of SUMWGT. I made a sample code to test on
>SASHELP.CLASS. What i found was once you specify the weight statement, SAS
>will adjust the weight on your analysis variable automatically. if you
omit
>the weight. by default, the weight will be 1. so,
>
>proc tabulate data = one missing ;
> class popu type mos ;
> var anal1 ;
> weight wgt;
> tables popu * type , mos*anal1 *(sum = 'Sum' mean = 'Mean') ;
> title4 "Weighted tabulate run for population*type*mos" ;
>run ;
>
>will do the work.
>
>Please run the folowing code and observe the difference. Sorry for taking
>you to the wrong direction.
>
>data class;
>set sashelp.class;
>if sex='F' then weight=1.25;
>else weight=0.83;
>run;
>
>proc sql;
>select sex,sum(height),mean(height)
> from class
> group by sex;
>quit;
>/*without weight adjustment*/
>proc tabulate data=class;
>class sex;
>var height;
>table sex, height*(sum mean);
>run;
>/*sumwgt and N are same becasue weight by default is 1*/
>proc tabulate data=class;
>class sex;
>var height;
>table sex, height*(N sumwgt='N' sum mean);
>run;
>/*Sumwgt has an effect on number of observation with weight statement.
mean
>keeps
> no changes, because the effect is cancelled out.*/
>proc tabulate data=class;
>class sex;
>var height;
>table sex, height*(N sumwgt='N' sum mean);
>run;
>
>
>On Wed, Feb 27, 2008 at 2:06 PM, Hari Nath <hari_s_nath@yahoo.com> wrote:
>
>> Thanks Yu for your answer.....gave me a good start....i could not find
>> much info from documentation......okay from your answer, usage of var
>> statement is needed as the requested analysis variables are sum and
>> mean....two ways i could think of, but dont know which one is
>> right....hope to get some help....
>>
>> *******method 1 with var and weight statement;
>> proc tabulate data = one missing ;
>> class popu type mos ;
>> var anal1 ;
>> weight weighted_anal1 ; ********weighted_anal1 = wgt * anal1;
>> tables popu * type , mos*anal1 *(sumwgt = 'Sum' mean = 'Mean') ;
>> title4 "Weighted tabulate run for population*type*mos" ;
>> run ;
>>
>> ********method 2 with var but no weight statement;
>> proc tabulate data = one missing ;
>> class popu type mos ;
>> var weighted_anal1 ; ********weighted_anal1 = wgt * anal1;
>> tables popu * type , mos*weighted_anal1 *(sumwgt = 'Sum' mean
= 'Mean') ;
>> title4 "Weighted tabulate run for population*type*mos" ;
>> run ;
>>
>> many thanks
>> hari.
>>
>>
>> On Wed, 27 Feb 2008 12:48:16 0600, Yu Zhang <zhangyu05@GMAIL.COM>
wrote:
>>
>> >Hi, Hari,
>> >
>> >You may try to create a new variable in your report dataset, say
>> >weighted_anal1=wgt*anal1.
>> >then in proc tabulate,
>> >
>> > proc tabulate data = one missing ;
>> > class popu type mos ;
>> > weight wgt ;
>> > tables popu * type , mos*(sumwgt = 'Sum' mean = 'Mean') ;
>> > title4 "Weighted tabulate run for population*type*mos" ;
>> >run ;
>> >
>> >I didn't test it with mock data. But the online doc says:
>> > SUMWGT
>> >
>> >is the sum of the weights, Wi, computed as: sigma Wi.
>> >
>> >HTH
>> >
>> >Yu
>> >
>> >
>> >
>> >On Wed, Feb 27, 2008 at 11:17 AM, Hari Nath <hari_s_nath@yahoo.com>
>> wrote:
>> >
>> >> Hi all,
>> >>
>> >> Normally i use weights for counts and most of time in proc
>> summary....but
>> >> now i need some help in figuring out to weight the sum and means in
>> proc
>> >> tabulate.....the 'wgt' variable is the weight and it is an integer
>> created
>> >> based on 'type' variable....can someone correct me with the right way
>> of
>> >> weighting here.......i looked at the archives and one example had to
>> >> multiply the weight variable somthing like
>> >> tables (popu*type)*wgt*sumwgt, mos*anal1 *(sum = 'Sum' mean
= 'Mean') ;
>> >>
>> >> which doesnt work for me.......
>> >>
>> >> many thanks
>> >> hari.
>> >>
>> >> ********my code;
>> >> proc tabulate data = one missing ;
>> >> class popu type mos ;
>> >> var anal1 ;
>> >> weight wgt ;
>> >> tables popu * type , mos*anal1 *(sum = 'Sum' mean = 'Mean') ;
>> >> title4 "Weighted tabulate run for population*type*mos" ;
>> >> run ;
>> >>
>>
