<?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 find out maximum value with group by condition ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-maximum-value-with-group-by-condition/m-p/445085#M111488</link>
    <description>&lt;P&gt;Try using the having statement&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;HAVING max(sum_sell) = sum_sell&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 13 Mar 2018 09:15:19 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2018-03-13T09:15:19Z</dc:date>
    <item>
      <title>How to find out maximum value with group by condition ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-maximum-value-with-group-by-condition/m-p/445080#M111487</link>
      <description>&lt;P&gt;How to find out Maximum value with group by condition and below is example but it didnt worked :-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA VISITS;&lt;BR /&gt;INPUT ID VISIT_DATE : MMDDYY10. sell @@;&lt;BR /&gt;FORMAT VISIT_DATE DATE9.;&lt;BR /&gt;DATALINES;&lt;BR /&gt;1 02/01/2003 180 1 03/02/2003 178 1 04/01/2003 170&lt;BR /&gt;2 03/03/2003 170 2 04/01/2003 172&lt;BR /&gt;3 04/01/2003 130 3 06/01/2003 128 3 08/01/2003 128&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;select id,max(sum_sell) from&lt;BR /&gt;(select id ,sum(sell) as sum_sell from VISITS&lt;BR /&gt;group by id )&lt;BR /&gt;group by id;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output :-&lt;/P&gt;&lt;P&gt;ID max_sell&lt;BR /&gt;------------------&lt;BR /&gt;1 528&lt;BR /&gt;2 342&lt;BR /&gt;3 386&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but expected output is&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ID max_sell&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 528&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;How to achieve this using proc sql ?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Mar 2018 09:06:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-maximum-value-with-group-by-condition/m-p/445080#M111487</guid>
      <dc:creator>MG18</dc:creator>
      <dc:date>2018-03-13T09:06:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to find out maximum value with group by condition ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-maximum-value-with-group-by-condition/m-p/445085#M111488</link>
      <description>&lt;P&gt;Try using the having statement&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;HAVING max(sum_sell) = sum_sell&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Mar 2018 09:15:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-maximum-value-with-group-by-condition/m-p/445085#M111488</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2018-03-13T09:15:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to find out maximum value with group by condition ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-maximum-value-with-group-by-condition/m-p/445088#M111490</link>
      <description>&lt;P&gt;The reason you get three records back is because:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  select id,&lt;BR /&gt;         max(sum_sell) &lt;BR /&gt;  from   (select id,sum(sell) as sum_sell from VISITS group by id)
  group by id;
quit;&lt;/PRE&gt;
&lt;P&gt;You group the outside select clause by ID.&amp;nbsp; That means for each distinct ID a row will appear in the output, if you have ID's 1,2,3 then thte output will have rows for 1,2,3.&amp;nbsp; Do you want the max across all ID's?&amp;nbsp; If so then drop the last group by.&amp;nbsp; If you don't, then you have the correct result.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Mar 2018 09:21:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-maximum-value-with-group-by-condition/m-p/445088#M111490</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-03-13T09:21:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to find out maximum value with group by condition ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-maximum-value-with-group-by-condition/m-p/445092#M111491</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Still it didnt worked&amp;nbsp; :&amp;lt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select id,&lt;BR /&gt;max(sum_sell)&lt;BR /&gt;from (select id,sum(sell) as sum_sell from VISITS group by id)&lt;BR /&gt;group by id&lt;BR /&gt;HAVING max(sum_sell) =sum_sell ;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;output :-&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&lt;BR /&gt;------------------&lt;BR /&gt;1 528&lt;BR /&gt;2 342&lt;BR /&gt;3 386&lt;/P&gt;</description>
      <pubDate>Tue, 13 Mar 2018 10:03:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-maximum-value-with-group-by-condition/m-p/445092#M111491</guid>
      <dc:creator>MG18</dc:creator>
      <dc:date>2018-03-13T10:03:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to find out maximum value with group by condition ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-maximum-value-with-group-by-condition/m-p/445093#M111492</link>
      <description>&lt;P&gt;DATA VISITS;&lt;BR /&gt;INPUT ID VISIT_DATE : MMDDYY10. sell @@;&lt;BR /&gt;FORMAT VISIT_DATE DATE9.;&lt;BR /&gt;DATALINES;&lt;BR /&gt;1 02/01/2003 180 1 03/02/2003 178 1 04/01/2003 170&lt;BR /&gt;2 03/03/2003 170 2 04/01/2003 172&lt;BR /&gt;3 04/01/2003 130 3 06/01/2003 128 3 08/01/2003 128&lt;BR /&gt;5 04/01/2003 130 5 06/01/2003 128 5 08/01/2003 128&lt;BR /&gt;5 04/01/2003 130 5 06/01/2003 128 5 08/01/2003 128&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;select * from (select id,sum(sell) as sum_sell from VISITS group by id ) where sum_sell =&lt;BR /&gt;(select&lt;BR /&gt;max(sum_sell) as sum_sell&lt;BR /&gt;from (select id,sum(sell) as sum_sell from VISITS group by id ) );&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is worked &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Mar 2018 10:11:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-maximum-value-with-group-by-condition/m-p/445093#M111492</guid>
      <dc:creator>MG18</dc:creator>
      <dc:date>2018-03-13T10:11:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to find out maximum value with group by condition ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-maximum-value-with-group-by-condition/m-p/445095#M111493</link>
      <description>&lt;P&gt;And what did not work with the code I provided?&amp;nbsp; All you have done is wrap my code into a where clause (i.e. adding more processing time)?&lt;/P&gt;</description>
      <pubDate>Tue, 13 Mar 2018 10:18:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-out-maximum-value-with-group-by-condition/m-p/445095#M111493</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-03-13T10:18:13Z</dc:date>
    </item>
  </channel>
</rss>

