<?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: Select row based on max value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Select-row-based-on-max-value/m-p/295747#M61837</link>
    <description>&lt;P&gt;Select cust, max(a) as maxA, max(b) as maxB, max(C) as MaxC, max( calculated maxA, calculated maxB, calculated maxC) as overallMax&lt;/P&gt;
&lt;P&gt;from have&lt;/P&gt;
&lt;P&gt;group by cust;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 01 Sep 2016 09:28:26 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-09-01T09:28:26Z</dc:date>
    <item>
      <title>Select row based on max value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-row-based-on-max-value/m-p/295742#M61835</link>
      <description>&lt;P&gt;DATA TEST;&lt;BR /&gt;INPUT CUST A B C;&lt;BR /&gt;CARDS;&lt;BR /&gt;1 12 13 14&lt;BR /&gt;1 12 13 11&lt;BR /&gt;2 12 10 14&lt;BR /&gt;2 12 17 14&lt;BR /&gt;3 10 16 11&lt;BR /&gt;3 10 13 14&lt;BR /&gt;4 12 11 14&lt;BR /&gt;4 12 11 14&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*the objective is to get aggregated max values per cust, and resulting one column which have max of a,b and c*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*this codes gives var wise aggregated max values but when i try to find for all a,b,c it gives error*/&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE ANA AS&lt;BR /&gt;SELECT CUST&lt;BR /&gt;,MAX(A) as max_a&lt;BR /&gt;,MAX(B) as max_b&lt;BR /&gt;,MAX(C) as max_c&lt;BR /&gt;from test&lt;BR /&gt;group by 1&lt;BR /&gt;;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE ANA AS&lt;BR /&gt;SELECT CUST&lt;BR /&gt;,MAX(max_a,max_b,max_c) as max_abc&lt;BR /&gt;from test&lt;BR /&gt;;quit;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2016 09:19:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-row-based-on-max-value/m-p/295742#M61835</guid>
      <dc:creator>farrukh</dc:creator>
      <dc:date>2016-09-01T09:19:10Z</dc:date>
    </item>
    <item>
      <title>Re: Select row based on max value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-row-based-on-max-value/m-p/295746#M61836</link>
      <description>&lt;P&gt;In order to reference new columns in SQL you can use the CALCULATED keyword&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See sample below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
  CREATE TABLE ANA AS
    SELECT CUST
      ,MAX(A) as max_a
      ,MAX(B) as max_b
      ,MAX(C) as max_c
      , max(calculated max_a,calculated max_b,calculated max_c) as maxValue 
    from test
      group by 1
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But one could run another query on the ANA table to create the max column&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bruno&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2016 09:28:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-row-based-on-max-value/m-p/295746#M61836</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2016-09-01T09:28:04Z</dc:date>
    </item>
    <item>
      <title>Re: Select row based on max value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-row-based-on-max-value/m-p/295747#M61837</link>
      <description>&lt;P&gt;Select cust, max(a) as maxA, max(b) as maxB, max(C) as MaxC, max( calculated maxA, calculated maxB, calculated maxC) as overallMax&lt;/P&gt;
&lt;P&gt;from have&lt;/P&gt;
&lt;P&gt;group by cust;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2016 09:28:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-row-based-on-max-value/m-p/295747#M61837</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-09-01T09:28:26Z</dc:date>
    </item>
  </channel>
</rss>

