<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Weighted standard deviation using proc means in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Weighted-standard-deviation-using-proc-means/m-p/181792#M46302</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am running a means on weighted data in both SAS and Stata and getting wildly different values for standard deviation.&amp;nbsp; The statistician here believes SAS is incorrect.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I took the class dataset from sashelp and created two fake weights.&amp;nbsp; t_wt gives everyone a weight of 1 and t_wt2 gives everyone a weight of 5.&amp;nbsp; When running means using each weight I had expected the standard deviation to remain the same as there is no variance in the means or data distribution.&amp;nbsp; (and in Stata, the standard deviation does remain the same).&amp;nbsp; However I am getting a shift in stddev from 22.77 to 50.92 for the weight variable and 5.12 to 11.46 for the height variable.&amp;nbsp; We are having problems explaining why the results are different in SAS and Stata.&amp;nbsp; Any thoughts?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data temp2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set sashelp.class;&lt;/P&gt;&lt;P&gt;&amp;nbsp; t_wt = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; t_wt2 = 5;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc means data = temp2 mean min max std n std;&lt;/P&gt;&lt;P&gt;&amp;nbsp; var weight height; &lt;/P&gt;&lt;P&gt;&amp;nbsp; weight t_wt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc means data = temp2 mean min max std n std;&lt;/P&gt;&lt;P&gt;&amp;nbsp; var weight height; &lt;/P&gt;&lt;P&gt;&amp;nbsp; weight t_wt2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 25 Feb 2015 19:42:11 GMT</pubDate>
    <dc:creator>MMcCracken</dc:creator>
    <dc:date>2015-02-25T19:42:11Z</dc:date>
    <item>
      <title>Weighted standard deviation using proc means</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Weighted-standard-deviation-using-proc-means/m-p/181792#M46302</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am running a means on weighted data in both SAS and Stata and getting wildly different values for standard deviation.&amp;nbsp; The statistician here believes SAS is incorrect.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I took the class dataset from sashelp and created two fake weights.&amp;nbsp; t_wt gives everyone a weight of 1 and t_wt2 gives everyone a weight of 5.&amp;nbsp; When running means using each weight I had expected the standard deviation to remain the same as there is no variance in the means or data distribution.&amp;nbsp; (and in Stata, the standard deviation does remain the same).&amp;nbsp; However I am getting a shift in stddev from 22.77 to 50.92 for the weight variable and 5.12 to 11.46 for the height variable.&amp;nbsp; We are having problems explaining why the results are different in SAS and Stata.&amp;nbsp; Any thoughts?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data temp2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set sashelp.class;&lt;/P&gt;&lt;P&gt;&amp;nbsp; t_wt = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; t_wt2 = 5;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc means data = temp2 mean min max std n std;&lt;/P&gt;&lt;P&gt;&amp;nbsp; var weight height; &lt;/P&gt;&lt;P&gt;&amp;nbsp; weight t_wt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc means data = temp2 mean min max std n std;&lt;/P&gt;&lt;P&gt;&amp;nbsp; var weight height; &lt;/P&gt;&lt;P&gt;&amp;nbsp; weight t_wt2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Feb 2015 19:42:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Weighted-standard-deviation-using-proc-means/m-p/181792#M46302</guid>
      <dc:creator>MMcCracken</dc:creator>
      <dc:date>2015-02-25T19:42:11Z</dc:date>
    </item>
    <item>
      <title>Re: Weighted standard deviation using proc means</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Weighted-standard-deviation-using-proc-means/m-p/181793#M46303</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think there's a note regarding this in the documentation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try using proc surveymeans instead.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EDIT: Look at the VARDEF= Options instead, which is the denominator for the variance/std calculation. The default is probably not what you want, most likely WGT or N instead. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;data temp2;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&amp;nbsp; set sashelp.class;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&amp;nbsp; t_wt = 1;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&amp;nbsp; t_wt2 = 5;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;proc means data = temp2 mean min max std n std vardef=WGT;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&amp;nbsp; var weight height; &lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&amp;nbsp; weight t_wt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;proc means data = temp2 mean min max std n std vardef=WGT;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&amp;nbsp; var weight height; &lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&amp;nbsp; weight t_wt2;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Feb 2015 21:18:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Weighted-standard-deviation-using-proc-means/m-p/181793#M46303</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-02-25T21:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: Weighted standard deviation using proc means</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Weighted-standard-deviation-using-proc-means/m-p/181794#M46304</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;PROC MEANS calculates the variance as the sum[weight*(x-xbar)^2]/d, where d can be different things. The default is d=n-1. Thus, you will get a very different variance and hence standard deviation by changing the weight from 1 to 5 (no adjustment for the magnitude of the weights).&amp;nbsp; You can adjust for the scale difference by using the statement option VARDEF=WEIGHT. Then, d = sum[weight]. Try:&lt;/P&gt;&lt;P&gt;proc means data = temp2 mean min max std n std VARDEF=WGT;&lt;/P&gt;&lt;P&gt;&amp;nbsp; var weight height; &lt;/P&gt;&lt;P&gt;&amp;nbsp; weight t_wt2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will get you close to the same variance and standard deviation as the original. You could also try VARDEF=WEIGHT to get d=sum[weight] - 1. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Feb 2015 22:10:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Weighted-standard-deviation-using-proc-means/m-p/181794#M46304</guid>
      <dc:creator>lvm</dc:creator>
      <dc:date>2015-02-25T22:10:09Z</dc:date>
    </item>
  </channel>
</rss>

