<?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 Min date/time by multiple groups in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Min-date-time-by-multiple-groups/m-p/468974#M119858</link>
    <description>Hey guys,&lt;BR /&gt;&lt;BR /&gt;I am trying to query the min date and min time by multiple groups but no luck.&lt;BR /&gt;&lt;BR /&gt;Sample data&lt;BR /&gt;&lt;BR /&gt;LOC CAR DATE TIME&lt;BR /&gt;A 123 5/10 02:35&lt;BR /&gt;A 123 5/10 13:45&lt;BR /&gt;B 123 5/12 04:45&lt;BR /&gt;B 123 5/15 00:35&lt;BR /&gt;B 124 5/10 15:55&lt;BR /&gt;C 123 5/17 12:00&lt;BR /&gt;C 124 5/11 05:30&lt;BR /&gt;C 124 5/12 18:00&lt;BR /&gt;&lt;BR /&gt;I want the result dataset to show&lt;BR /&gt;&lt;BR /&gt;LOC CAR DATE TIME&lt;BR /&gt;A 123 5/10 2:35&lt;BR /&gt;B 123 5/12 4:45&lt;BR /&gt;B 124 5/10 15:55&lt;BR /&gt;C 123 5/17 12:00&lt;BR /&gt;C 124 5/11 05:30&lt;BR /&gt;&lt;BR /&gt;So I want the minimum date and time for each car at each location.&lt;BR /&gt;&lt;BR /&gt;I tried proc sql but over partition by function isn’t allowed and the min function isn’t giving me the desired output.&lt;BR /&gt;&lt;BR /&gt;Any help would be greatly appreciated!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
    <pubDate>Sun, 10 Jun 2018 04:29:17 GMT</pubDate>
    <dc:creator>anhkha1205</dc:creator>
    <dc:date>2018-06-10T04:29:17Z</dc:date>
    <item>
      <title>Min date/time by multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Min-date-time-by-multiple-groups/m-p/468974#M119858</link>
      <description>Hey guys,&lt;BR /&gt;&lt;BR /&gt;I am trying to query the min date and min time by multiple groups but no luck.&lt;BR /&gt;&lt;BR /&gt;Sample data&lt;BR /&gt;&lt;BR /&gt;LOC CAR DATE TIME&lt;BR /&gt;A 123 5/10 02:35&lt;BR /&gt;A 123 5/10 13:45&lt;BR /&gt;B 123 5/12 04:45&lt;BR /&gt;B 123 5/15 00:35&lt;BR /&gt;B 124 5/10 15:55&lt;BR /&gt;C 123 5/17 12:00&lt;BR /&gt;C 124 5/11 05:30&lt;BR /&gt;C 124 5/12 18:00&lt;BR /&gt;&lt;BR /&gt;I want the result dataset to show&lt;BR /&gt;&lt;BR /&gt;LOC CAR DATE TIME&lt;BR /&gt;A 123 5/10 2:35&lt;BR /&gt;B 123 5/12 4:45&lt;BR /&gt;B 124 5/10 15:55&lt;BR /&gt;C 123 5/17 12:00&lt;BR /&gt;C 124 5/11 05:30&lt;BR /&gt;&lt;BR /&gt;So I want the minimum date and time for each car at each location.&lt;BR /&gt;&lt;BR /&gt;I tried proc sql but over partition by function isn’t allowed and the min function isn’t giving me the desired output.&lt;BR /&gt;&lt;BR /&gt;Any help would be greatly appreciated!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Sun, 10 Jun 2018 04:29:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Min-date-time-by-multiple-groups/m-p/468974#M119858</guid>
      <dc:creator>anhkha1205</dc:creator>
      <dc:date>2018-06-10T04:29:17Z</dc:date>
    </item>
    <item>
      <title>Re: Min date/time by multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Min-date-time-by-multiple-groups/m-p/468975#M119859</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select *
from have
group by loc,car
having date=min(date) and time=min(time);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 10 Jun 2018 04:36:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Min-date-time-by-multiple-groups/m-p/468975#M119859</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-10T04:36:32Z</dc:date>
    </item>
    <item>
      <title>Re: Min date/time by multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Min-date-time-by-multiple-groups/m-p/468978#M119862</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/183857"&gt;@anhkha1205&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;There is a glitch in&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt; SQL and it wouldn't return the desired result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want us to post tested code then please make the effort and post sample data in the form of a working and tested SAS data step as I've done below.&lt;/P&gt;
&lt;P&gt;Don't expect us to do&amp;nbsp;such prep work for you or else get less answers, slower and less responses and&amp;nbsp;untested code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover dlm=' ';
  input LOC $ CAR DATE:ddmmyy. TIME :time.;
  format date date9. time time.;
  datalines;
A 123 01/04/10 13:35
A 123 01/05/10 02:35
A 123 01/05/10 13:45
B 123 01/05/12 04:45
B 123 01/05/15 00:35
B 124 01/05/10 15:55
C 123 01/05/17 12:00
C 124 01/05/11 05:30
C 124 01/05/12 18:00
;
run;

proc sql;
  create table want as
    select *
    from have
    group by loc,car
    having (date*86400+time)=min((date*86400+time))
    ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 10 Jun 2018 05:25:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Min-date-time-by-multiple-groups/m-p/468978#M119862</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-06-10T05:25:01Z</dc:date>
    </item>
    <item>
      <title>Re: Min date/time by multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Min-date-time-by-multiple-groups/m-p/468990#M119870</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover dlm=' ';
  input LOC $ CAR DATE:ddmmyy. TIME :time.;
  format date date9. time time.;
  datalines;
A 123 01/04/10 13:35
A 123 01/05/10 02:35
A 123 01/05/10 13:45
B 123 01/05/12 04:45
B 123 01/05/15 00:35
B 124 01/05/10 15:55
C 123 01/05/17 12:00
C 124 01/05/11 05:30
C 124 01/05/12 18:00
;
run;
proc sort data=have;
by _all_;
run;
data want;
 set have;
 by loc car;
 if first.car;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 10 Jun 2018 10:22:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Min-date-time-by-multiple-groups/m-p/468990#M119870</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-06-10T10:22:13Z</dc:date>
    </item>
    <item>
      <title>Re: Min date/time by multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Min-date-time-by-multiple-groups/m-p/468999#M119875</link>
      <description>&lt;P&gt;This minimum by group is done very simply in PROC SUMMARY if you use actual SAS datetime values (which you should be using anyway). No sorting needed. No writing your own code in a datastep needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data = have nway;
    class loc car;
    var datetime;
    output out=want min=min_datetime;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 10 Jun 2018 11:47:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Min-date-time-by-multiple-groups/m-p/468999#M119875</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-06-10T11:47:21Z</dc:date>
    </item>
    <item>
      <title>Re: Min date/time by multiple groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Min-date-time-by-multiple-groups/m-p/469095#M119927</link>
      <description>&lt;P&gt;Similar to &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;'s code, maybe a bit less cryptic :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select 
    loc,
    car,
    dhms(date,hour(time),minute(time),0) as datetime format=datetime16.
from have
group by loc, car
having datetime = min(datetime);
quit; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Jun 2018 04:14:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Min-date-time-by-multiple-groups/m-p/469095#M119927</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-06-11T04:14:56Z</dc:date>
    </item>
  </channel>
</rss>

