<?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: Extract every last unique combination ordered by date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extract-every-last-unique-combination-ordered-by-date/m-p/486389#M126547</link>
    <description>&lt;P&gt;FWIW you need to be very careful discussing and naming variables related to time, dates and datetime values appropriately when dealing with SAS. Your "time" variable appears to be a date value. The reason is time in SAS values is measured in seconds and dates are measured in days. If you search this forum you find a number of discussion about code not behaving properly that eventually boiled down to misunderstanding this basic SAS measurement difference and why results were much different than expected.&lt;/P&gt;</description>
    <pubDate>Mon, 13 Aug 2018 15:28:04 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-08-13T15:28:04Z</dc:date>
    <item>
      <title>Extract every last unique combination ordered by date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-every-last-unique-combination-ordered-by-date/m-p/486066#M126380</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I'm having difficulty in extracting unique tasks performed by workers in events arranged by time. The unique combination is defined by ID and Mode. Following dataset mimics the scenario :&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; ID        Time       Mode     Event
 23456     20120101    A        Open
 23456     20120101    B        Closed
 87690     20120311    G        Closed
 98000     20120201    B        Open
 98000     20120301    A        Open
 98000     20120101    A        Open
 87889     20121009    C        Closed
 87889     20120101    C        Open
 87900     20120411    A        Closed
 87900     20120102    A        Closed&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;Hope for the following result:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; ID        Time       Mode     Event
 23456     20120101    A        Open
 23456     20120101    B        Closed
 87690     20120311    G        Closed
 98000     20120201    B        Open
 98000     20120301    A        Open
 87889     20121009    C        Closed
 87900     20120411    A        Closed&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;I will first sort by time in descending order:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  proc sort data=df; by ID descending time; run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;Then I can use sort again to get unique combo by ID and Mode:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  proc sort data=df dupout=nodup nodupkey;
     by ID Mode; run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In the last step, how do I ensure that the none-duped record is also the latest event?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Sat, 11 Aug 2018 17:22:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-every-last-unique-combination-ordered-by-date/m-p/486066#M126380</guid>
      <dc:creator>lydiawawa</dc:creator>
      <dc:date>2018-08-11T17:22:30Z</dc:date>
    </item>
    <item>
      <title>Re: Extract every last unique combination ordered by date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-every-last-unique-combination-ordered-by-date/m-p/486068#M126382</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID        Time :yymmdd10.       Mode  $   Event $;
cards;
 23456     20120101    A        Open
 23456     20120101    B        Closed
 87690     20120311    G        Closed
 98000     20120201    B        Open
 98000     20120301    A        Open
 98000     20120101    A        Open
 87889     20121009    C        Closed
 87889     20120101    C        Open
 87900     20120411    A        Closed
 87900     20120102    A        Closed
 ;

proc sql;
create table want as
select *
from have
group by id ,mode
having time=max(time)
order by id,time;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 11 Aug 2018 17:40:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-every-last-unique-combination-ordered-by-date/m-p/486068#M126382</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-11T17:40:35Z</dc:date>
    </item>
    <item>
      <title>Re: Extract every last unique combination ordered by date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-every-last-unique-combination-ordered-by-date/m-p/486069#M126383</link>
      <description>&lt;P&gt;Hi, Sorry I'm not with SAS. Just wondering, will this statement take care of duplicated combo of ID and mode? Thank you for the prompt reply! I think the first part of Sql arranges the data and the second part takes the latest date?&lt;/P&gt;</description>
      <pubDate>Sun, 12 Aug 2018 07:39:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-every-last-unique-combination-ordered-by-date/m-p/486069#M126383</guid>
      <dc:creator>lydiawawa</dc:creator>
      <dc:date>2018-08-12T07:39:02Z</dc:date>
    </item>
    <item>
      <title>Re: Extract every last unique combination ordered by date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-every-last-unique-combination-ordered-by-date/m-p/486070#M126384</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30435"&gt;@lydiawawa&lt;/a&gt;&amp;nbsp; Please test the code and let us know. If it doesn;t meet your needs , let's rework to meet your requirement.&amp;nbsp; I can't claim anything from my side. I am hoping you test carefully and diligently.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Aug 2018 17:57:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-every-last-unique-combination-ordered-by-date/m-p/486070#M126384</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-11T17:57:25Z</dc:date>
    </item>
    <item>
      <title>Re: Extract every last unique combination ordered by date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-every-last-unique-combination-ordered-by-date/m-p/486091#M126393</link>
      <description>&lt;P&gt;Sort, then select last in by-group:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID Time :yymmdd10. Mode $ Event $;
format time yymmdd10.;
datalines;
 23456     20120101    A        Open
 23456     20120101    B        Closed
 87690     20120311    G        Closed
 98000     20120201    B        Open
 98000     20120301    A        Open
 98000     20120101    A        Open
 87889     20121009    C        Closed
 87889     20120101    C        Open
 87900     20120411    A        Closed
 87900     20120102    A        Closed
 ;

proc sort data=have; by ID mode time; run;

data want;
set have; by ID mode;
if last.mode;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 11 Aug 2018 21:35:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-every-last-unique-combination-ordered-by-date/m-p/486091#M126393</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-08-11T21:35:44Z</dc:date>
    </item>
    <item>
      <title>Re: Extract every last unique combination ordered by date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-every-last-unique-combination-ordered-by-date/m-p/486389#M126547</link>
      <description>&lt;P&gt;FWIW you need to be very careful discussing and naming variables related to time, dates and datetime values appropriately when dealing with SAS. Your "time" variable appears to be a date value. The reason is time in SAS values is measured in seconds and dates are measured in days. If you search this forum you find a number of discussion about code not behaving properly that eventually boiled down to misunderstanding this basic SAS measurement difference and why results were much different than expected.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Aug 2018 15:28:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-every-last-unique-combination-ordered-by-date/m-p/486389#M126547</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-13T15:28:04Z</dc:date>
    </item>
  </channel>
</rss>

