<?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 Record with max date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Record-with-max-date/m-p/492752#M129545</link>
    <description>Hi,&lt;BR /&gt;I Have a table that has record with multiple dates. I need to create a dataset with each record with maximum date. The source table looks as below.&lt;BR /&gt;&lt;BR /&gt;ID STATE eff_date&lt;BR /&gt;123 CA 10/18/2017&lt;BR /&gt;123 CA 10/18/2017&lt;BR /&gt;123 NY 3/25/2018&lt;BR /&gt;123 NY 3/25/2018&lt;BR /&gt;234 AZ 1/1/2018&lt;BR /&gt;234 AZ 7/18/2018&lt;BR /&gt;234 ? 7/18/2018&lt;BR /&gt;I need to pick the ID and state with maximum effective date. I need to pick just one id and a state even though they have duplicates.&lt;BR /&gt;Any logic for this ?&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
    <pubDate>Wed, 05 Sep 2018 18:31:33 GMT</pubDate>
    <dc:creator>nickspencer</dc:creator>
    <dc:date>2018-09-05T18:31:33Z</dc:date>
    <item>
      <title>Record with max date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Record-with-max-date/m-p/492752#M129545</link>
      <description>Hi,&lt;BR /&gt;I Have a table that has record with multiple dates. I need to create a dataset with each record with maximum date. The source table looks as below.&lt;BR /&gt;&lt;BR /&gt;ID STATE eff_date&lt;BR /&gt;123 CA 10/18/2017&lt;BR /&gt;123 CA 10/18/2017&lt;BR /&gt;123 NY 3/25/2018&lt;BR /&gt;123 NY 3/25/2018&lt;BR /&gt;234 AZ 1/1/2018&lt;BR /&gt;234 AZ 7/18/2018&lt;BR /&gt;234 ? 7/18/2018&lt;BR /&gt;I need to pick the ID and state with maximum effective date. I need to pick just one id and a state even though they have duplicates.&lt;BR /&gt;Any logic for this ?&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Wed, 05 Sep 2018 18:31:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Record-with-max-date/m-p/492752#M129545</guid>
      <dc:creator>nickspencer</dc:creator>
      <dc:date>2018-09-05T18:31:33Z</dc:date>
    </item>
    <item>
      <title>Re: Record with max date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Record-with-max-date/m-p/492754#M129547</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input ID STATE $ eff_date : mmddyy10.;
format eff_date mmddyy10.;
cards;
123 CA 10/18/2017
123 CA 10/18/2017
123 NY 3/25/2018
123 NY 3/25/2018
234 AZ 1/1/2018
234 AZ 7/18/2018
;
proc sort data=have out=_have;
by id state descending eff_date;
run;


data want;
set _have;
by id state descending eff_date;
if first.state;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sort data=have out=_have;
by id state  eff_date;
run;


data want;
set _have;
by id state  eff_date;
if last.state;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;or&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 distinct *
from have
group by id,state
having eff_date=max(eff_date);
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Sep 2018 18:43:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Record-with-max-date/m-p/492754#M129547</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-05T18:43:30Z</dc:date>
    </item>
    <item>
      <title>Re: Record with max date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Record-with-max-date/m-p/492757#M129549</link>
      <description>&lt;P&gt;Which record do you want when the latest date is duplicated?&lt;/P&gt;</description>
      <pubDate>Wed, 05 Sep 2018 18:52:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Record-with-max-date/m-p/492757#M129549</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-09-05T18:52:04Z</dc:date>
    </item>
    <item>
      <title>Re: Record with max date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Record-with-max-date/m-p/492759#M129550</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt; I see the city values are same when eff date is duplicated while some have null values.</description>
      <pubDate>Wed, 05 Sep 2018 18:55:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Record-with-max-date/m-p/492759#M129550</guid>
      <dc:creator>nickspencer</dc:creator>
      <dc:date>2018-09-05T18:55:13Z</dc:date>
    </item>
    <item>
      <title>Re: Record with max date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Record-with-max-date/m-p/492760#M129551</link>
      <description>&lt;P&gt;Please provide us a better and comprehensive sample of what you have and your required output for the sample&lt;/P&gt;</description>
      <pubDate>Wed, 05 Sep 2018 19:01:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Record-with-max-date/m-p/492760#M129551</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-05T19:01:53Z</dc:date>
    </item>
    <item>
      <title>Re: Record with max date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Record-with-max-date/m-p/492764#M129552</link>
      <description>&lt;P&gt;Assuming you means STATE and not&amp;nbsp;CITY and that you prefer a record with a non missing STATE when there there is one but a missing STATE when it's the only one on the LAST eff_date :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input ID STATE $ eff_date :mmddyy.;
format eff_date yymmdd10.;
datalines;
123 CA 10/18/2017
123 CA 10/18/2017
123 NY 3/25/2018
123 NY 3/25/2018
234 AZ 1/1/2018
234 AZ 7/18/2018
234 . 7/18/2018
;

proc sort data=test out=last; 
by descending eff_date descending state; run;

data want; set last(obs=1); run;

proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Sep 2018 19:09:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Record-with-max-date/m-p/492764#M129552</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-09-05T19:09:39Z</dc:date>
    </item>
  </channel>
</rss>

