<?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: selecting maximum value for multiple variables on a table in SAS Health and Life Sciences</title>
    <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/selecting-maximum-value-for-multiple-variables-on-a-table/m-p/5962#M537</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&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; I just followed my colleagues without thinking completely. I think if I remove the field pmax_derated in the group by field, I get what I want - single record for sub_id. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 18 Jul 2013 17:56:40 GMT</pubDate>
    <dc:creator>saspert</dc:creator>
    <dc:date>2013-07-18T17:56:40Z</dc:date>
    <item>
      <title>selecting maximum value for multiple variables on a table</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/selecting-maximum-value-for-multiple-variables-on-a-table/m-p/5957#M532</link>
      <description>I have a table I want to select the maximum id for mulitple records and am having problems figuring out the code.  For example what I would like from the list below is &lt;BR /&gt;
&lt;BR /&gt;
123 b&lt;BR /&gt;
456 d&lt;BR /&gt;
678 f&lt;BR /&gt;
&lt;BR /&gt;
id        value&lt;BR /&gt;
&lt;BR /&gt;
123     a&lt;BR /&gt;
123     b&lt;BR /&gt;
456     c&lt;BR /&gt;
456     d&lt;BR /&gt;
678     e&lt;BR /&gt;
678     f&lt;BR /&gt;
&lt;BR /&gt;
I tried to do a proc sql statement that just brought back 678 f for example because it had the maximum values of all values on the table.&lt;BR /&gt;
&lt;BR /&gt;
Any assistance would be appreciated.</description>
      <pubDate>Tue, 18 Dec 2007 14:34:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/selecting-maximum-value-for-multiple-variables-on-a-table/m-p/5957#M532</guid>
      <dc:creator>michaela</dc:creator>
      <dc:date>2007-12-18T14:34:26Z</dc:date>
    </item>
    <item>
      <title>Re: selecting maximum value for multiple variables on a table</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/selecting-maximum-value-for-multiple-variables-on-a-table/m-p/5958#M533</link>
      <description>something like (assuming key is number and letter is ID )&lt;BR /&gt;
&lt;BR /&gt;
data data;        &lt;BR /&gt;
  input key id $ ;&lt;BR /&gt;
cards;            &lt;BR /&gt;
123 a             &lt;BR /&gt;
123 b             &lt;BR /&gt;
456 c             &lt;BR /&gt;
456 d             &lt;BR /&gt;
678 e             &lt;BR /&gt;
678 f             &lt;BR /&gt;
;                 &lt;BR /&gt;
proc sql ;&lt;BR /&gt;
 create table top_keys as &lt;BR /&gt;
     select * from data &lt;BR /&gt;
   group by key&lt;BR /&gt;
  having ID= max(ID) ;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
Won't work on many (non-SAS) platforms and SAS refers to remerging summary with detail.&lt;BR /&gt;
You may have to be concerned about cases where the largest ID is not unique within a key.</description>
      <pubDate>Tue, 18 Dec 2007 15:05:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/selecting-maximum-value-for-multiple-variables-on-a-table/m-p/5958#M533</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-12-18T15:05:36Z</dc:date>
    </item>
    <item>
      <title>selecting maximum value for multiple variables on a table</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/selecting-maximum-value-for-multiple-variables-on-a-table/m-p/5959#M534</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Add the group by statement to your sql code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you're doing in PROC SQL without pass through&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table top_keys as&lt;/P&gt;&lt;P&gt;select key, max(id) as max_value&lt;/P&gt;&lt;P&gt;from have&lt;/P&gt;&lt;P&gt;group by id;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I don't know why Peter is using the having clause, but I don't think you need it unless you want the max for each group in each row as well. If you do then can remerge in a second sql step to avoid the issue Peter has mentioned.&lt;/P&gt;&lt;P&gt;Generally, any variables in the group by statement can be included in the select statement.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Jul 2011 21:49:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/selecting-maximum-value-for-multiple-variables-on-a-table/m-p/5959#M534</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2011-07-12T21:49:06Z</dc:date>
    </item>
    <item>
      <title>Re: selecting maximum value for multiple variables on a table</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/selecting-maximum-value-for-multiple-variables-on-a-table/m-p/5960#M535</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I think I have the same question and similar code but it does not seem to be working.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; CREATE TABLE WORK.TD_TST AS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; SELECT t1.id,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; t1.read_time,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (MAX(t1.read_time)) FORMAT=DATETIME22.3 AS MAX_of_read_time,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; t1.pmax_derated,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* start_date */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (intnx('HOUR',TODAY(),-12)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ) LABEL="start_date" AS start_date&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM PBGMES.td_header t1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHERE&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; t1.id ='1...4'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GROUP BY t1.sub_id,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; t1.pmax_derated,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (CALCULATED start_date)&lt;/P&gt;&lt;P&gt;/*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; having t1.read_time = (MAX(t1.read_time))*/&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;id&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; read_time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; max_read_time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pmax_derated&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; start_date&lt;/P&gt;&lt;P&gt;130716041724&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 17JUL2013:13:07:49.000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 17JUL2013:13:07:49.000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -25200&lt;/P&gt;&lt;P&gt;130716041724&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 17JUL2013:14:54:01.000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 17JUL2013:14:54:01.000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 89.420417786 -25200&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;saspert&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Jul 2013 16:06:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/selecting-maximum-value-for-multiple-variables-on-a-table/m-p/5960#M535</guid>
      <dc:creator>saspert</dc:creator>
      <dc:date>2013-07-18T16:06:02Z</dc:date>
    </item>
    <item>
      <title>Re: selecting maximum value for multiple variables on a table</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/selecting-maximum-value-for-multiple-variables-on-a-table/m-p/5961#M536</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am not sure why you believe the query is not working, I see two records with the same sub_id and different pmax_derated values, so group by could be working.&amp;nbsp; But I wonder if the calculation of start_date is what you intended.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I see that you use 'hour' as the interval in intnx and then specify today's date as the start-from..&amp;nbsp; The today() function returns a date value; so there is a mis-match here.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you are trying to specify 12:00 noon yesterday as the start time, then you will need something like&amp;nbsp; (intnx('HOUR',&lt;STRONG&gt;dhms(&lt;/STRONG&gt;TODAY&lt;STRONG&gt;(),0,0,),-&lt;/STRONG&gt;12) The DHMS converts today's date value to a datetime value which the 'HOUR' interval will work on.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Hope this helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Jul 2013 16:44:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/selecting-maximum-value-for-multiple-variables-on-a-table/m-p/5961#M536</guid>
      <dc:creator>LarryWorley</dc:creator>
      <dc:date>2013-07-18T16:44:48Z</dc:date>
    </item>
    <item>
      <title>Re: selecting maximum value for multiple variables on a table</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/selecting-maximum-value-for-multiple-variables-on-a-table/m-p/5962#M537</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&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; I just followed my colleagues without thinking completely. I think if I remove the field pmax_derated in the group by field, I get what I want - single record for sub_id. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Jul 2013 17:56:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/selecting-maximum-value-for-multiple-variables-on-a-table/m-p/5962#M537</guid>
      <dc:creator>saspert</dc:creator>
      <dc:date>2013-07-18T17:56:40Z</dc:date>
    </item>
  </channel>
</rss>

