<?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: How to calculate a weighted geomean in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-weighted-geomean/m-p/770039#M244232</link>
    <description>Thanks so much PGStats, this is exactly what I was looking for!</description>
    <pubDate>Thu, 23 Sep 2021 20:36:45 GMT</pubDate>
    <dc:creator>sasuser61</dc:creator>
    <dc:date>2021-09-23T20:36:45Z</dc:date>
    <item>
      <title>How to calculate a weighted geomean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-weighted-geomean/m-p/770007#M244221</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to calculate a weighted geomean such that:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;City&lt;/TD&gt;&lt;TD&gt;Province&lt;/TD&gt;&lt;TD&gt;Price_Relative&lt;/TD&gt;&lt;TD&gt;Weight&lt;/TD&gt;&lt;TD&gt;Weighted_Geomean&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Montreal&lt;/TD&gt;&lt;TD&gt;QC&lt;/TD&gt;&lt;TD&gt;1.00321&lt;/TD&gt;&lt;TD&gt;0.65&lt;/TD&gt;&lt;TD&gt;1.003538&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Quebec&lt;/TD&gt;&lt;TD&gt;QC&lt;/TD&gt;&lt;TD&gt;1.00368&lt;/TD&gt;&lt;TD&gt;0.20&lt;/TD&gt;&lt;TD&gt;1.003538&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Gatineau&lt;/TD&gt;&lt;TD&gt;QC&lt;/TD&gt;&lt;TD&gt;1.00477&lt;/TD&gt;&lt;TD&gt;0.15&lt;/TD&gt;&lt;TD&gt;1.003538&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately, I can't seem to find a built in function that could perform this task. But, this is what I would love to be able to do (if it only existed):&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as

select *, sumproduct(price_relative ** weight) as weighted_geomean

from have

group by province;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Since sumproduct doesn't exist like it does in Excel, is there a simple work around? Or is there a built in function for weighted geomean that I just haven't come across?&lt;BR /&gt;&lt;BR /&gt;Thanks so much in advance!&lt;/P&gt;</description>
      <pubDate>Thu, 23 Sep 2021 18:49:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-weighted-geomean/m-p/770007#M244221</guid>
      <dc:creator>sasuser61</dc:creator>
      <dc:date>2021-09-23T18:49:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate a weighted geomean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-weighted-geomean/m-p/770016#M244225</link>
      <description>&lt;P&gt;Proc Surveymeans will calculated weighted geomeans.&lt;/P&gt;
&lt;P&gt;See if this helps:&lt;/P&gt;
&lt;PRE&gt;ods output domaingeomeans= mydataset;   
proc surveymeans data=have geomean;
   domain province;
   var   price_relative;
   weight weight;
run;&lt;/PRE&gt;
&lt;P&gt;Surveymeans uses the ODS OUTPUT to create output data sets. Domaingeomeans is the table that would have the geomean value by domain (your desired group variable(s)). You would need to join the result back to your data and rename the default output variable name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I really hope your weighted geomean is not actually expected to be the same for different provinces as shown in your "example".&lt;/P&gt;</description>
      <pubDate>Thu, 23 Sep 2021 19:30:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-weighted-geomean/m-p/770016#M244225</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-09-23T19:30:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate a weighted geomean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-weighted-geomean/m-p/770024#M244227</link>
      <description>&lt;P&gt;This is not a &lt;EM&gt;workaround&lt;/EM&gt;, it is how to get the &lt;EM&gt;correct&lt;/EM&gt; result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select *, exp(sum(log(price_relative)* weight) / sum(weight)) as weighted_geomean
from have
group by province;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(untested)&lt;/P&gt;</description>
      <pubDate>Thu, 23 Sep 2021 19:40:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-weighted-geomean/m-p/770024#M244227</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2021-09-23T19:40:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate a weighted geomean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-weighted-geomean/m-p/770039#M244232</link>
      <description>Thanks so much PGStats, this is exactly what I was looking for!</description>
      <pubDate>Thu, 23 Sep 2021 20:36:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-weighted-geomean/m-p/770039#M244232</guid>
      <dc:creator>sasuser61</dc:creator>
      <dc:date>2021-09-23T20:36:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate a weighted geomean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-weighted-geomean/m-p/770040#M244233</link>
      <description>Thanks so much ballardw! I really liked this option as well!</description>
      <pubDate>Thu, 23 Sep 2021 20:37:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-weighted-geomean/m-p/770040#M244233</guid>
      <dc:creator>sasuser61</dc:creator>
      <dc:date>2021-09-23T20:37:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate a weighted geomean</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-weighted-geomean/m-p/770210#M244339</link>
      <description>&lt;P&gt;Or using PROC UNIVARIATE :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc univariate data=sashelp.class outtable=want&amp;nbsp; noprint;&lt;/P&gt;
&lt;P&gt;var weight;&lt;/P&gt;
&lt;P&gt;weight height;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Check want table.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Sep 2021 12:41:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-a-weighted-geomean/m-p/770210#M244339</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-09-24T12:41:15Z</dc:date>
    </item>
  </channel>
</rss>

