<?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: (sort of) weighted average in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242376#M55802</link>
    <description>&lt;P&gt;Perhaps I am not understanding the problem, but I have to disagree with several of the submitted "solutions." The solution that you accepted as correct does not seem correct to me. Both &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4"&gt;@ChrisHemedinger﻿&lt;/a&gt; and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh﻿&lt;/a&gt;&amp;nbsp;suggested implementations of the formula sum(premium)/sum(fraction).&amp;nbsp; That is not the same as mean(premium/fraction), which I think is the correct formula.&lt;/P&gt;</description>
    <pubDate>Fri, 08 Jan 2016 14:57:21 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2016-01-08T14:57:21Z</dc:date>
    <item>
      <title>(sort of) weighted average</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242352#M55788</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone tell me how to calculate weighted averages in this example:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;data premium;
   input id fraction premium;
   datalines;
1 1 1000
2 0.5 500&lt;BR /&gt;run;
&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;Customers 1 and 2 both payed the same premium, but no. 2 was insured for only six months.&lt;BR /&gt;They the same annual premium, so in my opinion the average premium per person&amp;nbsp;is 1000.&lt;BR /&gt;However, using weight does not work correctly in this case:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;proc means mean;
weight fraction;
var premium;
run;
&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;It returns 833 as the average premium.&lt;BR /&gt;Currently I solve this by exporting means output, summing fraction and premium and divide.&lt;BR /&gt;&lt;BR /&gt;Does anyone know of an easy, better way - without calculating new variables in the datastep (there are many variables)?&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Eric&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2016 11:48:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242352#M55788</guid>
      <dc:creator>EH</dc:creator>
      <dc:date>2016-01-08T11:48:57Z</dc:date>
    </item>
    <item>
      <title>Re: (sort of) weighted average</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242355#M55790</link>
      <description>&lt;P&gt;You could use PROC SQL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select mean(premium/fraction) as mean_premium
from premium;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Jan 2016 12:17:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242355#M55790</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-08T12:17:27Z</dc:date>
    </item>
    <item>
      <title>Re: (sort of) weighted average</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242359#M55793</link>
      <description>&lt;P&gt;Thanks for asking your question on the communities here. &amp;nbsp;I see you've also asked it in other places (SAS-L, &lt;A href="http://blogs.sas.com/content/iml/2016/01/06/weighted-mean-in-sas.html#comments" target="_self"&gt;blog comments&lt;/A&gt;) so I want to add some more of that context.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems like you really want an "annualized premium" -- what each customer is paying per annum (year) as a rate. &amp;nbsp;If the term is something different that 1.0 years, you need a formula to calculate what the annual rate is.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've seen this answer on SAS-L by "retired mainframer":&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data null;
   set premium end=eof;
   do until (eof);
      sum+(premium/fraction);
      count+1;
   end;
   average = sum/count;
   put average=;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The SQL approach by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh﻿&lt;/a&gt;&amp;nbsp;might also serve your purpose.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2016 13:09:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242359#M55793</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2016-01-08T13:09:16Z</dc:date>
    </item>
    <item>
      <title>Re: (sort of) weighted average</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242360#M55794</link>
      <description>&lt;P&gt;Thanks Chris and Reinhard,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The next step is that I want the premiumpaid&amp;nbsp;by No 2 to weigh less than the premium paid&amp;nbsp;by No 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I change the case to&lt;/P&gt;
&lt;P&gt;Id 1, fraction=1, premium=900&lt;/P&gt;
&lt;P&gt;Id 2, fraction=0.5, premium=600&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The average annual premium should be (900 + 600)&amp;nbsp;/ 1.5 = 1000.&lt;/P&gt;
&lt;P&gt;In Reinhard's case it is (900 + 1200) / 2 = 1050.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can see it can be solved using Chris' script. But then I have dozens of variables I want to treat this way...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But thanks!! for your quick replies.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;Eric&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2016 13:15:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242360#M55794</guid>
      <dc:creator>EH</dc:creator>
      <dc:date>2016-01-08T13:15:05Z</dc:date>
    </item>
    <item>
      <title>Re: (sort of) weighted average</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242361#M55795</link>
      <description>&lt;P&gt;If you prefer SQL, I think this accomplishes something similar:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
   CREATE TABLE WORK.Avgs AS 
   SELECT   (COUNT(t1.id)) AS N, 
            (SUM(t1.fraction)) AS AnnumTotal, 
            (SUM(t1.premium)) AS PremiumTotal, 
          /* AnnualizedAvg */
            calculated PremiumTotal / calculated AnnumTotal AS AnnualizedAvg
      FROM WORK.PREMIUM t1;
QUIT;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Jan 2016 13:35:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242361#M55795</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2016-01-08T13:35:33Z</dc:date>
    </item>
    <item>
      <title>Re: (sort of) weighted average</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242362#M55796</link>
      <description>&lt;P&gt;Chris was faster and is correct.&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;What you want is the weighted mean of the annualized premiums with the fractions being the weights. This, indeed, amounts to (sum of premiums)/(sum of fractions) and hence can be calculated as shown by Chris or similarly as follows:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select sum(premium)/sum(fraction) as mean_premium
from premium;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Jan 2016 13:40:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242362#M55796</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-08T13:40:19Z</dc:date>
    </item>
    <item>
      <title>Re: (sort of) weighted average</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242363#M55797</link>
      <description>thx!</description>
      <pubDate>Fri, 08 Jan 2016 14:07:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242363#M55797</guid>
      <dc:creator>EH</dc:creator>
      <dc:date>2016-01-08T14:07:45Z</dc:date>
    </item>
    <item>
      <title>Re: (sort of) weighted average</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242364#M55798</link>
      <description>Thanks Chris and Reinhard. I feel a macro coming up...</description>
      <pubDate>Fri, 08 Jan 2016 14:08:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242364#M55798</guid>
      <dc:creator>EH</dc:creator>
      <dc:date>2016-01-08T14:08:15Z</dc:date>
    </item>
    <item>
      <title>Re: (sort of) weighted average</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242365#M55799</link>
      <description>&lt;P&gt;No, wait a minute! You don't need a macro. I can prepare an array solution for you.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2016 14:10:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242365#M55799</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-08T14:10:12Z</dc:date>
    </item>
    <item>
      <title>Re: (sort of) weighted average</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242366#M55800</link>
      <description>&lt;P&gt;So, you have more variables like PREMIUM, let's say three, for example: PREMIUM, VAR2, VAR3. And let's assume for a moment that the weights ("fractions") are the same for all these variables. (Or do you have individual fractions for each of them?)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case you could extend the DOW loop approach cited by Chris. But I'm afraid there is a correction necessary: The SET statement must be moved inside the DO-UNTIL loop (that's the trick of the DOW loop after all), otherwise we have an infinite loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now you can calculate the target variables, let's call them MEAN_PREMIUM, MEAN_VAR2 and MEAN_VAR3, as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data premium1;
input id fraction premium var2 var3;
cards;
1 1   1000 900 500
2 0.5 500  600 400
;

%let n=3; /* number of variables like PREMIUM */

data _null_;
array p[&amp;amp;n] premium var2 var3;
array s[&amp;amp;n];
array avg[&amp;amp;n] mean_premium mean_var2 mean_var3;
do until (eof);
  set premium1 end=eof;
  do i=1 to &amp;amp;n;
    s[i]+p[i];
  end;
  wgt+fraction;
end;
do i=1 to &amp;amp;n;
  avg[i] = s[i]/wgt;
end;
put avg(*)=;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you need individual fractions for each of the three variables, we could introduce a fourth array, which would be no problem at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2016 14:23:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242366#M55800</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-08T14:23:03Z</dc:date>
    </item>
    <item>
      <title>Re: (sort of) weighted average</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242371#M55801</link>
      <description>Reinhard, Thanks for your extensive reply. It is definitely something to apply in my case!</description>
      <pubDate>Fri, 08 Jan 2016 14:41:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242371#M55801</guid>
      <dc:creator>EH</dc:creator>
      <dc:date>2016-01-08T14:41:55Z</dc:date>
    </item>
    <item>
      <title>Re: (sort of) weighted average</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242376#M55802</link>
      <description>&lt;P&gt;Perhaps I am not understanding the problem, but I have to disagree with several of the submitted "solutions." The solution that you accepted as correct does not seem correct to me. Both &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4"&gt;@ChrisHemedinger﻿&lt;/a&gt; and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh﻿&lt;/a&gt;&amp;nbsp;suggested implementations of the formula sum(premium)/sum(fraction).&amp;nbsp; That is not the same as mean(premium/fraction), which I think is the correct formula.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2016 14:57:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242376#M55802</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-01-08T14:57:21Z</dc:date>
    </item>
    <item>
      <title>Re: (sort of) weighted average</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242379#M55803</link>
      <description>&lt;P&gt;Hello (again) Rick,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my data I have premiums and fractions of a year that a customer was insured.&lt;/P&gt;
&lt;P&gt;So in my opinion the average premium per customer is sum(premium)/sum(fraction). This is a sort of weighted average, unfortunately not supported by the MEANS procedure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So&amp;nbsp;being the&amp;nbsp;customer (who is always right &lt;img id="manwink" class="emoticon emoticon-manwink" src="https://communities.sas.com/i/smilies/16x16_man-wink.png" alt="Man Wink" title="Man Wink" /&gt;), I think the solutions are correct.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your thoughts!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers, Eric&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2016 15:13:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242379#M55803</guid>
      <dc:creator>EH</dc:creator>
      <dc:date>2016-01-08T15:13:26Z</dc:date>
    </item>
    <item>
      <title>Re: (sort of) weighted average</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242380#M55804</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS﻿&lt;/a&gt;: Well, mean(premium/fraction) was my first suggestion, but then&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/24420"&gt;@EH﻿&lt;/a&gt;&amp;nbsp;replied "&lt;SPAN&gt;I want the premium paid&amp;nbsp;by No 2 to weigh less than the premium paid&amp;nbsp;by No 1" and presented an example calculation that&amp;nbsp;led us to the sum(premium)/sum(fraction) solution.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2016 15:16:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242380#M55804</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-08T15:16:03Z</dc:date>
    </item>
    <item>
      <title>Re: (sort of) weighted average</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242381#M55805</link>
      <description>&lt;P&gt;There is a similar question, marked as solved, but I cannot find the solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Procedures/Weighted-average/m-p/24378#U24378" target="_blank"&gt;https://communities.sas.com/t5/SAS-Procedures/Weighted-average/m-p/24378#U24378&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the solution is referred to the VARDEF option, but that does not apply to the weighted mean calculation.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2016 15:21:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242381#M55805</guid>
      <dc:creator>EH</dc:creator>
      <dc:date>2016-01-08T15:21:14Z</dc:date>
    </item>
    <item>
      <title>Re: (sort of) weighted average</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242383#M55806</link>
      <description>If VARDEF is what you're looking for, here's the example from SAS doc: &lt;A href="https://support.sas.com/documentation/cdl/en/proc/68954/HTML/default/viewer.htm#n1xkqt7u5ylr2kn11174pq11od76.htm#n1934j4pmu3328n1hcczxemu170p" target="_blank"&gt;https://support.sas.com/documentation/cdl/en/proc/68954/HTML/default/viewer.htm#n1xkqt7u5ylr2kn11174pq11od76.htm#n1934j4pmu3328n1hcczxemu170p&lt;/A&gt;

&lt;P&gt;

You will need to read through it to see if you can apply that to your situation.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2016 15:25:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242383#M55806</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2016-01-08T15:25:20Z</dc:date>
    </item>
    <item>
      <title>Re: (sort of) weighted average</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242398#M55807</link>
      <description>&lt;P&gt;Fine with me. You can use any formula you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One reason you won't find this in a SAS procedure is that it is not a mean (weighted or otherwise). In terms of terminology, I would call&amp;nbsp;the formula sum(x)/sum(y)&amp;nbsp;a&lt;EM&gt; scaled sum. &lt;/EM&gt;Notice that if you reorder the weight values, you will get the same scaled sum. The "fraction" values are not attached to the "premium" values in any way, so you'll get the same answer for&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1 0.5 1000
2 1    500
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and for&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1 -99   1000
2 100.5  500&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Good luck with your analysis.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2016 16:22:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242398#M55807</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-01-08T16:22:42Z</dc:date>
    </item>
    <item>
      <title>Re: (sort of) weighted average</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242587#M55817</link>
      <description>&lt;P&gt;Hi Eric,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using Sum(premium)/Sum(Fraction) will not give you the right answer if you are wanting to calculated a weighted average where the weights are the fraction of the year that a premium was paid. From your original example, the Sum(Premium) = 900 + 600 =1500 and Sum(Fraction) = 1.0 + 0.5 = 1.5. As a result, 1500/1.5 = 1000. How can the average of the two premiums be more than either one of them ( 900 or 600). This makes no sense.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you sum up the product of the premium and fraction and then divide by the sum of the fraction that will and should give you a weighted average for the two premiums ((1.0)(900) +(0.5)(600))/(1.0 + 0.5) = 1200/ 1.5 = 800.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token procnames"&gt;&lt;STRONG&gt;&lt;FONT color="#000080"&gt;proc&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;&lt;STRONG&gt;&lt;FONT color="#000080"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;&lt;FONT color="#999999"&gt;;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="token statement"&gt;&lt;FONT color="#0000ff"&gt;select&lt;/FONT&gt;&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;&lt;FONT color="#0000ff"&gt;sum&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;&lt;FONT color="#999999"&gt;(&lt;/FONT&gt;&lt;/SPAN&gt;premium*fraction&lt;SPAN class="token punctuation"&gt;&lt;FONT color="#999999"&gt;)&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&lt;FONT color="#a67f59"&gt;/&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;&lt;FONT color="#0000ff"&gt;sum&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;&lt;FONT color="#999999"&gt;(&lt;/FONT&gt;&lt;/SPAN&gt;fraction&lt;SPAN class="token punctuation"&gt;&lt;FONT color="#999999"&gt;)&lt;/FONT&gt;&lt;/SPAN&gt; as mean_premium&lt;BR /&gt;&lt;SPAN class="token keyword"&gt;&lt;FONT color="#0000ff"&gt;from&lt;/FONT&gt;&lt;/SPAN&gt; premium&lt;SPAN class="token punctuation"&gt;&lt;FONT color="#999999"&gt;;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class="token procnames"&gt;&lt;STRONG&gt;&lt;FONT color="#000080"&gt;quit;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;&lt;FONT color="#999999"&gt;;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Jan 2016 03:10:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242587#M55817</guid>
      <dc:creator>twildone</dc:creator>
      <dc:date>2016-01-10T03:10:14Z</dc:date>
    </item>
    <item>
      <title>Re: (sort of) weighted average</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242664#M55839</link>
      <description>Hello Twildone,&lt;BR /&gt;You are right about the "makes no sense" part. This is "a sort of weighted average", it is the average yearly premium. If you multiply that by the number of weights (fractions) you get the total received premium.&lt;BR /&gt;In proc means, the weighted average is calculated as sum(WiXi)/sum(Wi), where my "sort of" requires sum(Xi)/sum(Wi). I am afraid I have to calculate this outside proc means, as suggested by others. Thanks anyway for your thoughts!</description>
      <pubDate>Mon, 11 Jan 2016 08:21:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242664#M55839</guid>
      <dc:creator>EH</dc:creator>
      <dc:date>2016-01-11T08:21:41Z</dc:date>
    </item>
    <item>
      <title>Re: (sort of) weighted average</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242665#M55840</link>
      <description>And thanks to this simple question, since friday I received five (5) badges. I'm so happy &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Mon, 11 Jan 2016 08:24:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sort-of-weighted-average/m-p/242665#M55840</guid>
      <dc:creator>EH</dc:creator>
      <dc:date>2016-01-11T08:24:56Z</dc:date>
    </item>
  </channel>
</rss>

