<?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: Getting the Maximum in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Getting-the-Maximum/m-p/286824#M58912</link>
    <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An example creating a new datetime value, with just the date and the hour, then use SQL for grouping&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile cards;
  input
    someDT anydtdtm.
  ;

  groupValue = dhms(datepart(someDT), hour(timepart(someDT)), 0 , 0);
  format
    someDT datetime22.3
    groupValue datetime22.3
  ;
cards;
18JUL2016:03:08:01
18JUL2016:03:23:40
18JUL2016:03:39:16
18JUL2016:03:54:51
18JUL2016:04:10:30
18JUL2016:04:26:08
18JUL2016:04:41:43
18JUL2016:04:57:20
18JUL2016:05:13:03
18JUL2016:05:28:40
18JUL2016:05:44:15
18JUL2016:05:59:53
18JUL2016:06:15:28
18JUL2016:06:31:07
18JUL2016:06:46:42
18JUL2016:07:02:17
18JUL2016:07:17:55
18JUL2016:07:33:31
18JUL2016:07:49:14
18JUL2016:08:04:51
18JUL2016:08:20:45
18JUL2016:08:36:27
18JUL2016:08:52:05
;

Proc sql;
  create table want as
  select
    groupValue
    , timePart(max(someDT)) as maxSomeTime format=time8.
  from  
    have
  group by
    groupValue
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bruno&lt;/P&gt;</description>
    <pubDate>Mon, 25 Jul 2016 11:36:29 GMT</pubDate>
    <dc:creator>BrunoMueller</dc:creator>
    <dc:date>2016-07-25T11:36:29Z</dc:date>
    <item>
      <title>Getting the Maximum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-the-Maximum/m-p/286809#M58906</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have these data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;18JUL2016:03:08:01&lt;BR /&gt;18JUL2016:03:23:40&lt;BR /&gt;18JUL2016:03:39:16&lt;BR /&gt;18JUL2016:03:54:51&lt;BR /&gt;18JUL2016:04:10:30&lt;BR /&gt;18JUL2016:04:26:08&lt;BR /&gt;18JUL2016:04:41:43&lt;BR /&gt;18JUL2016:04:57:20&lt;BR /&gt;18JUL2016:05:13:03&lt;BR /&gt;18JUL2016:05:28:40&lt;BR /&gt;18JUL2016:05:44:15&lt;BR /&gt;18JUL2016:05:59:53&lt;BR /&gt;18JUL2016:06:15:28&lt;BR /&gt;18JUL2016:06:31:07&lt;BR /&gt;18JUL2016:06:46:42&lt;BR /&gt;18JUL2016:07:02:17&lt;BR /&gt;18JUL2016:07:17:55&lt;BR /&gt;18JUL2016:07:33:31&lt;BR /&gt;18JUL2016:07:49:14&lt;BR /&gt;18JUL2016:08:04:51&lt;BR /&gt;18JUL2016:08:20:45&lt;BR /&gt;18JUL2016:08:36:27&lt;BR /&gt;18JUL2016:08:52:05&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and I wanted to get the maximum time on each hour. May I know the ways to solve this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jul 2016 10:36:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-the-Maximum/m-p/286809#M58906</guid>
      <dc:creator>jei</dc:creator>
      <dc:date>2016-07-25T10:36:21Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the Maximum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-the-Maximum/m-p/286816#M58907</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data intermediate;
set have;
date = datepart(datetimevalue);
hour = hour(datetimevalue);
run:

data want;
set intermediate;
by date hour;
if last.hour;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Jul 2016 10:53:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-the-Maximum/m-p/286816#M58907</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-07-25T10:53:33Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the Maximum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-the-Maximum/m-p/286818#M58908</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for replying. But when I'm submiting the code I only get the very last hour not the maximum time of each hour and when I'm removing the "if last.hour" of the code, I'm getting the exact output.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jul 2016 11:07:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-the-Maximum/m-p/286818#M58908</guid>
      <dc:creator>jei</dc:creator>
      <dc:date>2016-07-25T11:07:19Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the Maximum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-the-Maximum/m-p/286820#M58909</link>
      <description>&lt;P&gt;If your data is sorted correctly the last record per hour should be the largest.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please explain how this is not working.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jul 2016 11:23:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-the-Maximum/m-p/286820#M58909</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-07-25T11:23:15Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the Maximum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-the-Maximum/m-p/286823#M58911</link>
      <description>&lt;P&gt;This:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input datetimevalue datetime19.;
format datetimevalue datetime19.;
cards;
18JUL2016:03:08:01
18JUL2016:03:23:40
18JUL2016:03:39:16
18JUL2016:03:54:51
18JUL2016:04:10:30
18JUL2016:04:26:08
18JUL2016:04:41:43
18JUL2016:04:57:20
18JUL2016:05:13:03
18JUL2016:05:28:40
18JUL2016:05:44:15
18JUL2016:05:59:53
18JUL2016:06:15:28
18JUL2016:06:31:07
18JUL2016:06:46:42
18JUL2016:07:02:17
18JUL2016:07:17:55
18JUL2016:07:33:31
18JUL2016:07:49:14
18JUL2016:08:04:51
18JUL2016:08:20:45
18JUL2016:08:36:27
18JUL2016:08:52:05
;
run;

data intermediate;
set have;
date = datepart(datetimevalue);
format date date9.;
hour = hour(datetimevalue);
run;

data want;
set intermediate;
by date hour;
if last.hour;
run;

proc print noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;produces this result:&lt;/P&gt;
&lt;PRE&gt;     datetimevalue         date    hour

18JUL2016:03:54:51    18JUL2016      3 
18JUL2016:04:57:20    18JUL2016      4 
18JUL2016:05:59:53    18JUL2016      5 
18JUL2016:06:46:42    18JUL2016      6 
18JUL2016:07:49:14    18JUL2016      7 
18JUL2016:08:52:05    18JUL2016      8 
&lt;/PRE&gt;
&lt;P&gt;If you get something different, show code and log, please.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jul 2016 11:32:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-the-Maximum/m-p/286823#M58911</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-07-25T11:32:46Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the Maximum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-the-Maximum/m-p/286824#M58912</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An example creating a new datetime value, with just the date and the hour, then use SQL for grouping&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile cards;
  input
    someDT anydtdtm.
  ;

  groupValue = dhms(datepart(someDT), hour(timepart(someDT)), 0 , 0);
  format
    someDT datetime22.3
    groupValue datetime22.3
  ;
cards;
18JUL2016:03:08:01
18JUL2016:03:23:40
18JUL2016:03:39:16
18JUL2016:03:54:51
18JUL2016:04:10:30
18JUL2016:04:26:08
18JUL2016:04:41:43
18JUL2016:04:57:20
18JUL2016:05:13:03
18JUL2016:05:28:40
18JUL2016:05:44:15
18JUL2016:05:59:53
18JUL2016:06:15:28
18JUL2016:06:31:07
18JUL2016:06:46:42
18JUL2016:07:02:17
18JUL2016:07:17:55
18JUL2016:07:33:31
18JUL2016:07:49:14
18JUL2016:08:04:51
18JUL2016:08:20:45
18JUL2016:08:36:27
18JUL2016:08:52:05
;

Proc sql;
  create table want as
  select
    groupValue
    , timePart(max(someDT)) as maxSomeTime format=time8.
  from  
    have
  group by
    groupValue
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bruno&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jul 2016 11:36:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-the-Maximum/m-p/286824#M58912</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2016-07-25T11:36:29Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the Maximum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-the-Maximum/m-p/287056#M58998</link>
      <description>&lt;PRE&gt;

data have;
input datetimevalue datetime19.;
format datetimevalue datetime19.;
cards;
18JUL2016:03:08:01
18JUL2016:03:23:40
18JUL2016:03:39:16
18JUL2016:03:54:51
18JUL2016:04:10:30
18JUL2016:04:26:08
18JUL2016:04:41:43
18JUL2016:04:57:20
18JUL2016:05:13:03
18JUL2016:05:28:40
18JUL2016:05:44:15
18JUL2016:05:59:53
18JUL2016:06:15:28
18JUL2016:06:31:07
18JUL2016:06:46:42
18JUL2016:07:02:17
18JUL2016:07:17:55
18JUL2016:07:33:31
18JUL2016:07:49:14
18JUL2016:08:04:51
18JUL2016:08:20:45
18JUL2016:08:36:27
18JUL2016:08:52:05
;
run;
proc sql;
select *
 from have
  group by datepart(datetimevalue),hour(datetimevalue)
   having datetimevalue=max(datetimevalue);
quit;

&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Jul 2016 01:29:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-the-Maximum/m-p/287056#M58998</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-07-26T01:29:20Z</dc:date>
    </item>
    <item>
      <title>Re: Getting the Maximum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Getting-the-Maximum/m-p/287063#M59001</link>
      <description>&lt;P&gt;It works!&lt;/P&gt;&lt;P&gt;Thank you very much&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser﻿&lt;/a&gt;&amp;nbsp;&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;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jul 2016 01:57:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Getting-the-Maximum/m-p/287063#M59001</guid>
      <dc:creator>jei</dc:creator>
      <dc:date>2016-07-26T01:57:56Z</dc:date>
    </item>
  </channel>
</rss>

