<?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 Work around for GEOMEAN and HARMEAN not available in PROC MEANS? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Work-around-for-GEOMEAN-and-HARMEAN-not-available-in-PROC-MEANS/m-p/14973#M2546</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Reeza,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks for the replies.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After my first attempt with PROC MEANS failed, I also tried to create a table within PROC SQL using ‘group by’ to subset accordingly, but it never worked. After looking at your expression for geometric mean [that is, exp(mean(log(height)))], I realize the expression I used was incorrect. For some reason the mathematic formula I created in excel doesn’t work in SAS. I think it has something to do with array formulas.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In any case, both your SQL and data step method work to produce the correct geometric and harmonic mean! I am not that familiar with the table ODS destination, so I think I will stick with the SQL statement method instead.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again for your help!&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 03 Jan 2012 02:25:00 GMT</pubDate>
    <dc:creator>PQK</dc:creator>
    <dc:date>2012-01-03T02:25:00Z</dc:date>
    <item>
      <title>Work around for GEOMEAN and HARMEAN not available in PROC MEANS?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Work-around-for-GEOMEAN-and-HARMEAN-not-available-in-PROC-MEANS/m-p/14969#M2542</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;Dear Forum,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;I am trying to output the geometric and harmonic mean for one variable that is subsetted by two other variables. As a reference, I would like to calculate GEOMEAN and HARMEAN just as PROC MEANS would do in the following example.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;SPAN style="font-size: 8pt;"&gt;&lt;STRONG&gt;&lt;SPAN lang="EN-US" style="color: navy; background-color: white; font-family: 'Courier New';"&gt;proc&lt;/SPAN&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;SPAN lang="EN-US" style="color: navy; background-color: white; font-family: 'Courier New';"&gt;means&lt;/SPAN&gt;&lt;/STRONG&gt; &lt;SPAN lang="EN-US" style="color: blue; background-color: white; font-family: 'Courier New';"&gt;data&lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="color: black; background-color: white; font-family: 'Courier New';"&gt;=inputdata &lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="color: blue; background-color: white; font-family: 'Courier New';"&gt;noprint maxdec&lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="color: black; background-color: white; font-family: 'Courier New';"&gt;=&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN lang="EN-US" style="color: teal; background-color: white; font-family: 'Courier New';"&gt;2&lt;/SPAN&gt;&lt;/STRONG&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;SPAN style="font-size: 8pt;"&gt;&lt;SPAN lang="EN-US" style="color: blue; background-color: white; font-family: 'Courier New';"&gt;var&lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="color: black; background-color: white; font-family: 'Courier New';"&gt; var3;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;SPAN style="font-size: 8pt;"&gt;&lt;SPAN lang="EN-US" style="color: blue; background-color: white; font-family: 'Courier New';"&gt;class&lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="color: black; background-color: white; font-family: 'Courier New';"&gt; var1 var2;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;SPAN style="font-size: 8pt;"&gt;&lt;SPAN lang="EN-US" style="color: blue; background-color: white; font-family: 'Courier New';"&gt;output&lt;/SPAN&gt; &lt;SPAN lang="EN-US" style="color: blue; background-color: white; font-family: 'Courier New';"&gt;out&lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="color: black; background-color: white; font-family: 'Courier New';"&gt;=outputdata Mean(var3)=Mean;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;&lt;STRONG&gt;&lt;SPAN lang="EN-US" style="color: navy; background-color: white; font-family: 'Courier New';"&gt;run&lt;/SPAN&gt;&lt;/STRONG&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;PROC MEANS accomplishes this task easily for the arithmetic mean, but I am stuck trying to find a work around for geometric and harmonic mean…sigh.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;Any suggestions would be greatly appreciated.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Dec 2011 02:48:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Work-around-for-GEOMEAN-and-HARMEAN-not-available-in-PROC-MEANS/m-p/14969#M2542</guid>
      <dc:creator>PQK</dc:creator>
      <dc:date>2011-12-15T02:48:58Z</dc:date>
    </item>
    <item>
      <title>Work around for GEOMEAN and HARMEAN not available in PROC MEANS?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Work-around-for-GEOMEAN-and-HARMEAN-not-available-in-PROC-MEANS/m-p/14970#M2543</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I checked the documentation. there are not such options.&lt;/P&gt;&lt;P&gt;But at Function, I found these two functions to calculate these means.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data mean;
 set sashelp.class;
 geomean=geomean(age,weight,height);
 harmean=harmean(age,weight,height);
run;




&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Dec 2011 06:32:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Work-around-for-GEOMEAN-and-HARMEAN-not-available-in-PROC-MEANS/m-p/14970#M2543</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-12-15T06:32:06Z</dc:date>
    </item>
    <item>
      <title>Work around for GEOMEAN and HARMEAN not available in PROC MEANS?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Work-around-for-GEOMEAN-and-HARMEAN-not-available-in-PROC-MEANS/m-p/14971#M2544</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can use proc transpose and the functions that KSharp has suggested, or use some transformations with proc means. I prefer the transformations as its easier for me to understand. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For geometric mean take the log of your variable and then exponentiate the resulting mean of the logged variable. &lt;/P&gt;&lt;P&gt;For harmonic mean take the inverse of your variable and then n/sum(inverse) is the number you're looking for. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data class;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set sashelp.class;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; harm=1/height;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; geom=log(height);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ods table summary=step1;&lt;/P&gt;&lt;P&gt;proc means data=class n mean sum;&lt;/P&gt;&lt;P&gt;class sex;&lt;/P&gt;&lt;P&gt;var height harm geom;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data step2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set step1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; geometric_mean=exp(geom_mean);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; harmonic_mean=harm_n/harm_sum;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; keep sex height_mean geometric_mean harmonic_mean;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can verify it using KSharps formulas:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=class;&lt;/P&gt;&lt;P&gt;by sex;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc transpose data=class out=class2;&lt;/P&gt;&lt;P&gt;by sex;&lt;/P&gt;&lt;P&gt;var height;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data class3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set class2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mean=mean(of col:);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; harmean=harmean(of col:);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; geomean=geomean(of col:);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Dec 2011 17:50:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Work-around-for-GEOMEAN-and-HARMEAN-not-available-in-PROC-MEANS/m-p/14971#M2544</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2011-12-15T17:50:40Z</dc:date>
    </item>
    <item>
      <title>Work around for GEOMEAN and HARMEAN not available in PROC MEANS?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Work-around-for-GEOMEAN-and-HARMEAN-not-available-in-PROC-MEANS/m-p/14972#M2545</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually, Proc SQL is much clearer...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table summary as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select sex, mean(height) as avg_height, count(height)/sum(1/height) as harm_mean, exp(mean(log(height))) as geom_mean&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from sashelp.class&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by sex;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Dec 2011 17:53:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Work-around-for-GEOMEAN-and-HARMEAN-not-available-in-PROC-MEANS/m-p/14972#M2545</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2011-12-15T17:53:23Z</dc:date>
    </item>
    <item>
      <title>Work around for GEOMEAN and HARMEAN not available in PROC MEANS?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Work-around-for-GEOMEAN-and-HARMEAN-not-available-in-PROC-MEANS/m-p/14973#M2546</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Reeza,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks for the replies.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After my first attempt with PROC MEANS failed, I also tried to create a table within PROC SQL using ‘group by’ to subset accordingly, but it never worked. After looking at your expression for geometric mean [that is, exp(mean(log(height)))], I realize the expression I used was incorrect. For some reason the mathematic formula I created in excel doesn’t work in SAS. I think it has something to do with array formulas.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In any case, both your SQL and data step method work to produce the correct geometric and harmonic mean! I am not that familiar with the table ODS destination, so I think I will stick with the SQL statement method instead.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again for your help!&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Jan 2012 02:25:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Work-around-for-GEOMEAN-and-HARMEAN-not-available-in-PROC-MEANS/m-p/14973#M2546</guid>
      <dc:creator>PQK</dc:creator>
      <dc:date>2012-01-03T02:25:00Z</dc:date>
    </item>
  </channel>
</rss>

