<?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 Average of top 5 cheapest in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Average-of-top-5-cheapest/m-p/891555#M43581</link>
    <description>&lt;P&gt;In the attached file, each&amp;nbsp;File_Ref represent a risk profile. Then the premium of providers is listed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using the code below, I was able to rank the premiums grouped by each file reference&lt;/P&gt;&lt;PRE&gt;%_eg_conditional_dropds(WORK.QUERY_FOR_MSM_OUTPUT_0001);

PROC SQL;
   CREATE TABLE WORK.QUERY_FOR_MSM_OUTPUT_0001 AS 
   SELECT t1.File_Ref, 
          t1.'Provider Code'n, 
          t1.Provider, 
          t1.'Single Trip Premium'n, 
          t1.'Annual Premium'n, 
          t1.'Medical Value'n, 
          t1.'Medical Excess'n, 
          t1.'Baggage Value'n, 
          t1.'Baggage Excess'n, 
          t1.'Cancellation Value'n, 
          t1.'Cancellation Excess'n, 
          t1.'Defaqto Rating'n, 
          t1.'Personal Money Value'n, 
          t1.'Personal Money Excess'n, 
          t1.Cover, 
          t1.'New ST Premium'n, 
          t1.'New AMT Premium'n, 
          /* Premium */
            (t1.'New ST Premium'n+t1.'New AMT Premium'n) AS Premium
      FROM WORK.QUERY_FOR_MSM_OUTPUT t1
      ORDER BY t1.File_Ref,
               Premium;
QUIT;


proc rank data=WORK.QUERY_FOR_MSM_OUTPUT_0001 out=results ties=low ;
   by File_Ref;
   var 'Premium'n;
   ranks PremiumRank;
run;&lt;/PRE&gt;&lt;P&gt;Now, I would like to get the average premium of the top 5. I.e., the average premium of the top 5 cheapest quotes.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="actuarial_0-1693326221550.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/87275i2F9B1B4DF3245A32/image-size/medium?v=v2&amp;amp;px=400" role="button" title="actuarial_0-1693326221550.png" alt="actuarial_0-1693326221550.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;In Excel, the average if function gave the desired answer.&amp;nbsp;&lt;SPAN&gt;&lt;SPAN class=""&gt;Then all other values in the columns are populated with the same average value as above&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 29 Aug 2023 16:25:08 GMT</pubDate>
    <dc:creator>actuarial</dc:creator>
    <dc:date>2023-08-29T16:25:08Z</dc:date>
    <item>
      <title>Average of top 5 cheapest</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Average-of-top-5-cheapest/m-p/891555#M43581</link>
      <description>&lt;P&gt;In the attached file, each&amp;nbsp;File_Ref represent a risk profile. Then the premium of providers is listed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using the code below, I was able to rank the premiums grouped by each file reference&lt;/P&gt;&lt;PRE&gt;%_eg_conditional_dropds(WORK.QUERY_FOR_MSM_OUTPUT_0001);

PROC SQL;
   CREATE TABLE WORK.QUERY_FOR_MSM_OUTPUT_0001 AS 
   SELECT t1.File_Ref, 
          t1.'Provider Code'n, 
          t1.Provider, 
          t1.'Single Trip Premium'n, 
          t1.'Annual Premium'n, 
          t1.'Medical Value'n, 
          t1.'Medical Excess'n, 
          t1.'Baggage Value'n, 
          t1.'Baggage Excess'n, 
          t1.'Cancellation Value'n, 
          t1.'Cancellation Excess'n, 
          t1.'Defaqto Rating'n, 
          t1.'Personal Money Value'n, 
          t1.'Personal Money Excess'n, 
          t1.Cover, 
          t1.'New ST Premium'n, 
          t1.'New AMT Premium'n, 
          /* Premium */
            (t1.'New ST Premium'n+t1.'New AMT Premium'n) AS Premium
      FROM WORK.QUERY_FOR_MSM_OUTPUT t1
      ORDER BY t1.File_Ref,
               Premium;
QUIT;


proc rank data=WORK.QUERY_FOR_MSM_OUTPUT_0001 out=results ties=low ;
   by File_Ref;
   var 'Premium'n;
   ranks PremiumRank;
run;&lt;/PRE&gt;&lt;P&gt;Now, I would like to get the average premium of the top 5. I.e., the average premium of the top 5 cheapest quotes.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="actuarial_0-1693326221550.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/87275i2F9B1B4DF3245A32/image-size/medium?v=v2&amp;amp;px=400" role="button" title="actuarial_0-1693326221550.png" alt="actuarial_0-1693326221550.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;In Excel, the average if function gave the desired answer.&amp;nbsp;&lt;SPAN&gt;&lt;SPAN class=""&gt;Then all other values in the columns are populated with the same average value as above&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2023 16:25:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Average-of-top-5-cheapest/m-p/891555#M43581</guid>
      <dc:creator>actuarial</dc:creator>
      <dc:date>2023-08-29T16:25:08Z</dc:date>
    </item>
    <item>
      <title>Re: Average of top 5 cheapest</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Average-of-top-5-cheapest/m-p/891558#M43582</link>
      <description>&lt;P&gt;For this to work, I think you need the use the DESCENDING option in PROC RANK.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* UNTESTED CODE */
proc summary data=results nway;
    by file_ref;
    var premiumrank;
    output out=average mean=avgmarkettop5;
run;
data want;
    merge query_for_msm_output_0001 average(keep=file_ref avgmarkettop5);
    by file_ref;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want tested code, you ahve to provide the data as working SAS data step code (&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;examples and instructions&lt;/A&gt;), and not via attachments, and not using any other method.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2023 16:50:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Average-of-top-5-cheapest/m-p/891558#M43582</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-08-29T16:50:07Z</dc:date>
    </item>
    <item>
      <title>Re: Average of top 5 cheapest</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Average-of-top-5-cheapest/m-p/891565#M43583</link>
      <description>&lt;P&gt;Thank you so much for your help and advice!&lt;/P&gt;&lt;P&gt;The script is:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%_eg_conditional_dropds(WORK.QUERY_FOR_MSM_OUTPUT_0001);

PROC SQL;
   CREATE TABLE WORK.QUERY_FOR_MSM_OUTPUT_0001 AS 
   SELECT t1.File_Ref, 
          t1.'Provider Code'n, 
          t1.Provider, 
          t1.'Single Trip Premium'n, 
          t1.'Annual Premium'n, 
          t1.'Medical Value'n, 
          t1.'Medical Excess'n, 
          t1.'Baggage Value'n, 
          t1.'Baggage Excess'n, 
          t1.'Cancellation Value'n, 
          t1.'Cancellation Excess'n, 
          t1.'Defaqto Rating'n, 
          t1.'Personal Money Value'n, 
          t1.'Personal Money Excess'n, 
          t1.Cover, 
          t1.'New ST Premium'n, 
          t1.'New AMT Premium'n, 
          /* Premium */
            (t1.'New ST Premium'n+t1.'New AMT Premium'n) AS Premium
      FROM WORK.QUERY_FOR_MSM_OUTPUT t1
      ORDER BY t1.File_Ref,
               Premium;
QUIT;


proc rank data=WORK.QUERY_FOR_MSM_OUTPUT_0001 out=results ties=low descending;
   by File_Ref;
   var 'Premium'n;
   ranks PremiumRank;
run;

proc summary data=results nway;
    by file_ref;
    var premiumrank;
    output out=average mean=avgmarkettop5;
run;
data want;
    merge query_for_msm_output_0001 average(keep=file_ref avgmarkettop5);
    by file_ref;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So I pasted your script, and obtained the "want" table&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="actuarial_0-1693330065704.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/87277i5B5C6EF977850DAC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="actuarial_0-1693330065704.png" alt="actuarial_0-1693330065704.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;But the "average market top 5" appears to be too large. The cheapest 5 quotes are&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;14.3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;14.67&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;14.96&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;15.3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;15.45&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;which should give an average value of&amp;nbsp;14.936&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2023 17:31:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Average-of-top-5-cheapest/m-p/891565#M43583</guid>
      <dc:creator>actuarial</dc:creator>
      <dc:date>2023-08-29T17:31:55Z</dc:date>
    </item>
    <item>
      <title>Re: Average of top 5 cheapest</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Average-of-top-5-cheapest/m-p/891567#M43584</link>
      <description>&lt;P&gt;My mistake, try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=results(where=(premiumrank&amp;lt;=5)) nway;
    by file_ref;
    var premium;
    output out=average mean=avgmarkettop5;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Aug 2023 17:43:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Average-of-top-5-cheapest/m-p/891567#M43584</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-08-29T17:43:46Z</dc:date>
    </item>
  </channel>
</rss>

