<?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: dedeplicating on most recent date in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/dedeplicating-on-most-recent-date/m-p/32809#M7936</link>
    <description>Consolidated from related post:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
You have a couple of options - one is to perform two sorts with ay BY ID DESCENDING DATE; on the first sort and then followed with a SORT NODUPKEY EQUALS and a BY ID; statement.&lt;BR /&gt;
&lt;BR /&gt;
The other option is to again sort with ID DESCENDING DATE, and then use a SAS DATA step with a SET and a BY ID; statement -- and use BY GROUP processing with IF FIRST.ID processing to subset your input and only capture the first occurence of ID values.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
&lt;BR /&gt;
Suggested Google advanced search argument on this topic:&lt;BR /&gt;
&lt;BR /&gt;
data step by group processing site:sas.com</description>
    <pubDate>Wed, 30 Dec 2009 21:52:58 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-12-30T21:52:58Z</dc:date>
    <item>
      <title>dedeplicating on most recent date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/dedeplicating-on-most-recent-date/m-p/32802#M7929</link>
      <description>How do you deduplicate based on most recent date?&lt;BR /&gt;
&lt;BR /&gt;
PROC SORT data=total;&lt;BR /&gt;
by week ID;&lt;BR /&gt;
run;&lt;BR /&gt;
PROC FREQ DATA = total noprint;&lt;BR /&gt;
by week;&lt;BR /&gt;
table ID/ out = ID_DUPS  (keep = week ID Count where = (Count &amp;gt; 1)) ;&lt;BR /&gt;
run;&lt;BR /&gt;
 PROC PRINT DATA = ID_DUPS;&lt;BR /&gt;
 run;</description>
      <pubDate>Fri, 18 Dec 2009 19:42:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/dedeplicating-on-most-recent-date/m-p/32802#M7929</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-12-18T19:42:00Z</dc:date>
    </item>
    <item>
      <title>Re: dedeplicating on most recent date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/dedeplicating-on-most-recent-date/m-p/32803#M7930</link>
      <description>for the last week within an ID use:&lt;BR /&gt;
&lt;BR /&gt;
PROC SORT data=total;&lt;BR /&gt;
by ID week ;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data total;&lt;BR /&gt;
set total;&lt;BR /&gt;
by ID week;&lt;BR /&gt;
if last.ID;&lt;BR /&gt;
run;</description>
      <pubDate>Fri, 18 Dec 2009 19:49:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/dedeplicating-on-most-recent-date/m-p/32803#M7930</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2009-12-18T19:49:14Z</dc:date>
    </item>
    <item>
      <title>Re: dedeplicating on most recent date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/dedeplicating-on-most-recent-date/m-p/32804#M7931</link>
      <description>Thanks. How do you deduplicate selecting for the latest date within a week?  There's a unique time/date stamp field within each week.</description>
      <pubDate>Fri, 18 Dec 2009 20:19:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/dedeplicating-on-most-recent-date/m-p/32804#M7931</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-12-18T20:19:25Z</dc:date>
    </item>
    <item>
      <title>Re: dedeplicating on most recent date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/dedeplicating-on-most-recent-date/m-p/32805#M7932</link>
      <description>Separate the DATEPART (it's a function in SAS) to create a SAS DATE variable and use it with your BY processing.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 18 Dec 2009 20:24:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/dedeplicating-on-most-recent-date/m-p/32805#M7932</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-12-18T20:24:12Z</dc:date>
    </item>
    <item>
      <title>Re: dedeplicating on most recent date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/dedeplicating-on-most-recent-date/m-p/32806#M7933</link>
      <description>Thanks. Once I get SAS to create a SAS date, how do I ask SAS to identify the  most recent date and select for it?</description>
      <pubDate>Fri, 18 Dec 2009 20:28:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/dedeplicating-on-most-recent-date/m-p/32806#M7933</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-12-18T20:28:54Z</dc:date>
    </item>
    <item>
      <title>Re: dedeplicating on most recent date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/dedeplicating-on-most-recent-date/m-p/32807#M7934</link>
      <description>Refer to your other related post for info on BY GROUP processing.&lt;BR /&gt;
&lt;BR /&gt;
Scott</description>
      <pubDate>Fri, 18 Dec 2009 21:45:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/dedeplicating-on-most-recent-date/m-p/32807#M7934</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-12-18T21:45:22Z</dc:date>
    </item>
    <item>
      <title>Re: dedeplicating on most recent date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/dedeplicating-on-most-recent-date/m-p/32808#M7935</link>
      <description>Thanks!</description>
      <pubDate>Wed, 30 Dec 2009 19:48:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/dedeplicating-on-most-recent-date/m-p/32808#M7935</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-12-30T19:48:24Z</dc:date>
    </item>
    <item>
      <title>Re: dedeplicating on most recent date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/dedeplicating-on-most-recent-date/m-p/32809#M7936</link>
      <description>Consolidated from related post:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
You have a couple of options - one is to perform two sorts with ay BY ID DESCENDING DATE; on the first sort and then followed with a SORT NODUPKEY EQUALS and a BY ID; statement.&lt;BR /&gt;
&lt;BR /&gt;
The other option is to again sort with ID DESCENDING DATE, and then use a SAS DATA step with a SET and a BY ID; statement -- and use BY GROUP processing with IF FIRST.ID processing to subset your input and only capture the first occurence of ID values.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
&lt;BR /&gt;
Suggested Google advanced search argument on this topic:&lt;BR /&gt;
&lt;BR /&gt;
data step by group processing site:sas.com</description>
      <pubDate>Wed, 30 Dec 2009 21:52:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/dedeplicating-on-most-recent-date/m-p/32809#M7936</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-12-30T21:52:58Z</dc:date>
    </item>
    <item>
      <title>Re: dedeplicating on most recent date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/dedeplicating-on-most-recent-date/m-p/32810#M7937</link>
      <description>&amp;gt; Thanks. How do you deduplicate selecting for the&lt;BR /&gt;
&amp;gt; latest date within a week?  There's a unique&lt;BR /&gt;
&amp;gt; time/date stamp field within each week.&lt;BR /&gt;
&lt;BR /&gt;
Depending on how you're using this:&lt;BR /&gt;
&lt;BR /&gt;
Proc summary data=(input data) nway;&lt;BR /&gt;
   class id week;&lt;BR /&gt;
   var (variable with date/time stamp as a SAS datetime variable);&lt;BR /&gt;
   output out=(output data set name) max=;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
May want to have option (drop= _type_ _freq_) with the output data. The output dataset will have the largest date/time within each combination of ID and WEEK. As a side effect the output data will be sorted by ID and week but no sort is needed beforehand.</description>
      <pubDate>Sat, 09 Jan 2010 00:08:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/dedeplicating-on-most-recent-date/m-p/32810#M7937</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2010-01-09T00:08:54Z</dc:date>
    </item>
    <item>
      <title>Re: dedeplicating on most recent date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/dedeplicating-on-most-recent-date/m-p/32811#M7938</link>
      <description>I hope this example code will point you into the right direction.&lt;BR /&gt;
&lt;BR /&gt;
The main idea is to use intnx() to align your datestamps to the date of the last day of the week the datestamp value is from (Sunday) and use this additional variable "LastDayInWeek" for sorting.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data have;&lt;BR /&gt;
  id=1;&lt;BR /&gt;
  format DT datetime20.;&lt;BR /&gt;
  DT='19Dec2009 00:00:00'dt;&lt;BR /&gt;
  do while (DT lt '05Jan2010 00:00:00'dt);&lt;BR /&gt;
    output;&lt;BR /&gt;
    DT=sum(DT,ranuni(1)*86400);&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  create view VSortedByIDAndWeekAndDate as&lt;BR /&gt;
  select *, datepart(intnx('dtweek.2',DT,0,'E')) format=weekdatx. as LastDayInWeek&lt;BR /&gt;
   from have&lt;BR /&gt;
   order by id,LastDayInWeek,DT&lt;BR /&gt;
  ;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
data want;&lt;BR /&gt;
  set VSortedByIDAndWeekAndDate;&lt;BR /&gt;
  by id LastDayInWeek DT;&lt;BR /&gt;
  if last.LastDayInWeek then output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc print data=want;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick</description>
      <pubDate>Sat, 09 Jan 2010 08:27:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/dedeplicating-on-most-recent-date/m-p/32811#M7938</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2010-01-09T08:27:59Z</dc:date>
    </item>
  </channel>
</rss>

