<?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 Re: WEIGHT calculation in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/WEIGHT-calculation/m-p/157056#M41174</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It's a weighted average&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://en.wikipedia.org/wiki/Weighted_arithmetic_mean" title="http://en.wikipedia.org/wiki/Weighted_arithmetic_mean"&gt;Weighted arithmetic mean - Wikipedia, the free encyclopedia&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Additionally you need to account for missing and negative weights separately&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" cellpadding="6" cellspacing="0"&gt;&lt;TBODY&gt;&lt;TR valign="top"&gt;&lt;TD width="27%"&gt;Weight value...&lt;/TD&gt;&lt;TD width="71%"&gt;&lt;A name="a001093503"&gt; &lt;/A&gt; PROC MEANS...&lt;/TD&gt;&lt;/TR&gt;&lt;TR valign="top"&gt;&lt;TD width="27%"&gt;&lt;A name="a001093504"&gt; &lt;/A&gt; 0&lt;/TD&gt;&lt;TD width="71%"&gt;&lt;A name="a001093505"&gt; &lt;/A&gt; counts the observation in the total number of observations&lt;/TD&gt;&lt;/TR&gt;&lt;TR valign="top"&gt;&lt;TD width="27%"&gt;&lt;A name="a001093506"&gt; &lt;/A&gt; less than 0&lt;/TD&gt;&lt;TD width="71%"&gt;&lt;A name="a001093507"&gt; &lt;/A&gt; converts the value to zero and counts the observation in the total number of observations&lt;/TD&gt;&lt;/TR&gt;&lt;TR valign="top"&gt;&lt;TD width="27%"&gt;&lt;A name="a001093508"&gt; &lt;/A&gt; missing&lt;/TD&gt;&lt;TD width="71%"&gt;&lt;A name="a001093509"&gt; &lt;/A&gt; excludes the observation&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 28 Nov 2013 15:54:11 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2013-11-28T15:54:11Z</dc:date>
    <item>
      <title>WEIGHT calculation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/WEIGHT-calculation/m-p/157051#M41169</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In order to measure performance and whether we can reduce any execution time, I am trying to convert some of SAS code into SQL query. While doing it, I came across a piece of code weight is being calculated. Need to know how SAS calculates weight for any given column so that I can try and replicate the same using SQL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; background-color: #ffffff;"&gt;proc means data=input_file noprint;&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; background-color: #ffffff;"&gt;var C_A/weight=T_A;&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; background-color: #ffffff;"&gt;by period;&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; background-color: #ffffff;"&gt;output out=output_file &lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; background-color: #ffffff;"&gt;mean=&lt;/P&gt;&lt;P style="color: #222222; font-family: arial, sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P&gt;Any insight on this would be of great help to me.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;ankur&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Nov 2013 06:28:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/WEIGHT-calculation/m-p/157051#M41169</guid>
      <dc:creator>Ankur</dc:creator>
      <dc:date>2013-11-27T06:28:19Z</dc:date>
    </item>
    <item>
      <title>Re: WEIGHT calculation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/WEIGHT-calculation/m-p/157052#M41170</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The formulas used are&amp;nbsp; - if not obvious - normally documented as part of the documentation for the procedure.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Not sure if changing everything to SQL will help you a lot unless the data tables are stored in a data base. If stored in a data base: You might want to investigate the in-database capabilities of some of the PROCs (eg. Proc Means).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The quickest way of improving performance is in my experience to reduce passes through the data, reduction of volumes as fast as possible, re-design lookups (eg. by using hash tables).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Nov 2013 08:51:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/WEIGHT-calculation/m-p/157052#M41170</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2013-11-27T08:51:45Z</dc:date>
    </item>
    <item>
      <title>Re: WEIGHT calculation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/WEIGHT-calculation/m-p/157053#M41171</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Patrick, Appreciate your response and I do agree with the Performance improvement point. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But as per the assignment, I need some way to do it in SQL. If some one could provide a sample input/output with the weight function, then I can re-engineer it to see how its calculated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks &amp;amp; Best Regards,&lt;/P&gt;&lt;P&gt;Ankur Vatsal&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Nov 2013 10:00:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/WEIGHT-calculation/m-p/157053#M41171</guid>
      <dc:creator>Ankur</dc:creator>
      <dc:date>2013-11-27T10:00:28Z</dc:date>
    </item>
    <item>
      <title>Re: WEIGHT calculation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/WEIGHT-calculation/m-p/157054#M41172</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It would take two passes through the data to get the same result in SQL, but the final formula would be:&lt;/P&gt;&lt;P&gt;C_A*weight/sum_of_weights as weighted_mean&lt;/P&gt;&lt;P&gt;where the sum of weights would need to be calculated for each period.&amp;nbsp; You would need to join the summed weights back to the original data.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Nov 2013 15:33:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/WEIGHT-calculation/m-p/157054#M41172</guid>
      <dc:creator>MarkFisher</dc:creator>
      <dc:date>2013-11-28T15:33:24Z</dc:date>
    </item>
    <item>
      <title>Re: WEIGHT calculation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/WEIGHT-calculation/m-p/157055#M41173</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I clicked too soon--the weighted mean for each period would be the sum of C_A*weight divided by the sum of the weights, for each period.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Nov 2013 15:36:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/WEIGHT-calculation/m-p/157055#M41173</guid>
      <dc:creator>MarkFisher</dc:creator>
      <dc:date>2013-11-28T15:36:04Z</dc:date>
    </item>
    <item>
      <title>Re: WEIGHT calculation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/WEIGHT-calculation/m-p/157056#M41174</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It's a weighted average&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://en.wikipedia.org/wiki/Weighted_arithmetic_mean" title="http://en.wikipedia.org/wiki/Weighted_arithmetic_mean"&gt;Weighted arithmetic mean - Wikipedia, the free encyclopedia&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Additionally you need to account for missing and negative weights separately&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" cellpadding="6" cellspacing="0"&gt;&lt;TBODY&gt;&lt;TR valign="top"&gt;&lt;TD width="27%"&gt;Weight value...&lt;/TD&gt;&lt;TD width="71%"&gt;&lt;A name="a001093503"&gt; &lt;/A&gt; PROC MEANS...&lt;/TD&gt;&lt;/TR&gt;&lt;TR valign="top"&gt;&lt;TD width="27%"&gt;&lt;A name="a001093504"&gt; &lt;/A&gt; 0&lt;/TD&gt;&lt;TD width="71%"&gt;&lt;A name="a001093505"&gt; &lt;/A&gt; counts the observation in the total number of observations&lt;/TD&gt;&lt;/TR&gt;&lt;TR valign="top"&gt;&lt;TD width="27%"&gt;&lt;A name="a001093506"&gt; &lt;/A&gt; less than 0&lt;/TD&gt;&lt;TD width="71%"&gt;&lt;A name="a001093507"&gt; &lt;/A&gt; converts the value to zero and counts the observation in the total number of observations&lt;/TD&gt;&lt;/TR&gt;&lt;TR valign="top"&gt;&lt;TD width="27%"&gt;&lt;A name="a001093508"&gt; &lt;/A&gt; missing&lt;/TD&gt;&lt;TD width="71%"&gt;&lt;A name="a001093509"&gt; &lt;/A&gt; excludes the observation&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Nov 2013 15:54:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/WEIGHT-calculation/m-p/157056#M41174</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-11-28T15:54:11Z</dc:date>
    </item>
  </channel>
</rss>

