<?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: Identifying the record with the earliest date. in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Identifying-the-record-with-the-earliest-date/m-p/920057#M41213</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input recordID uniqueid date:ddmmyy10.;
format date ddmmyy10.;
datalines;
1234625 55 08/03/2006
1234632 72 06/03/2005
1234634 8 11/11/1997
1234636 104 09/03/2007
1234650 88 12/10/1999
1234617 55 05/12/2000
;
run;

proc sort data=have out=temp;
by uniqueid date;
run;
data want;
 set temp;
 by uniqueid;
 if first.uniqueid and last.uniqueid then want=0;
  else want=ifn(first.uniqueid,1,0);
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 13 Mar 2024 05:46:11 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2024-03-13T05:46:11Z</dc:date>
    <item>
      <title>Identifying the record with the earliest date.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Identifying-the-record-with-the-earliest-date/m-p/920056#M41212</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I have a data set where each record is identified by a record id. Multiple records share a similar unique id based on identifying individuals. Some records with same unique id have different dates.&lt;/P&gt;
&lt;P&gt;Could I identify the record with the unique id that has the earliest date by creating a flag variable with 0 (for no) and 1 (for yes) values?&lt;/P&gt;
&lt;P&gt;sample code below:&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input recordID uniqueid date:ddmmyy10.;&lt;BR /&gt;format date ddmmyy10.;&lt;BR /&gt;datalines;&lt;/P&gt;
&lt;P&gt;1234625 55 08/03/2006&lt;BR /&gt;1234632 72 06/03/2005&lt;BR /&gt;1234634 8 11/11/1997&lt;BR /&gt;1234636 104 09/03/2007&lt;BR /&gt;1234650 88 12/10/1999&lt;BR /&gt;1234617 55 05/12/2000&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;input recordID uniqueid date:ddmmyy10. flag;&lt;BR /&gt;format date ddmmyy10.;&lt;BR /&gt;datalines;&lt;/P&gt;
&lt;P&gt;1234625 55 08/03/2006 0&lt;BR /&gt;1234632 72 06/03/2005 0&lt;BR /&gt;1234634 8 11/11/1997 0&lt;BR /&gt;1234636 104 09/03/2007 0&lt;BR /&gt;1234650 88 12/10/1999 0&lt;BR /&gt;1234617 55 05/12/2000 1&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2024 05:19:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Identifying-the-record-with-the-earliest-date/m-p/920056#M41212</guid>
      <dc:creator>Ihsan-Mahdi</dc:creator>
      <dc:date>2024-03-13T05:19:49Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying the record with the earliest date.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Identifying-the-record-with-the-earliest-date/m-p/920057#M41213</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input recordID uniqueid date:ddmmyy10.;
format date ddmmyy10.;
datalines;
1234625 55 08/03/2006
1234632 72 06/03/2005
1234634 8 11/11/1997
1234636 104 09/03/2007
1234650 88 12/10/1999
1234617 55 05/12/2000
;
run;

proc sort data=have out=temp;
by uniqueid date;
run;
data want;
 set temp;
 by uniqueid;
 if first.uniqueid and last.uniqueid then want=0;
  else want=ifn(first.uniqueid,1,0);
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Mar 2024 05:46:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Identifying-the-record-with-the-earliest-date/m-p/920057#M41213</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-03-13T05:46:11Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying the record with the earliest date.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Identifying-the-record-with-the-earliest-date/m-p/920071#M41215</link>
      <description>&lt;P&gt;I think this would do the same:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;want = ifn(first.uniqueid and not last.uniqueid,1,0);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or, done with IF:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if first.uniqueid and not last,uniqueid
then want = 1;
else want = 0;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To get the want dataset as shown in the original question, an additional sort by recordid is required.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2024 08:16:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Identifying-the-record-with-the-earliest-date/m-p/920071#M41215</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-03-13T08:16:55Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying the record with the earliest date.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Identifying-the-record-with-the-earliest-date/m-p/920133#M41216</link>
      <description>&lt;P&gt;Thank you so much! This worked great!&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2024 14:25:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Identifying-the-record-with-the-earliest-date/m-p/920133#M41216</guid>
      <dc:creator>Ihsan-Mahdi</dc:creator>
      <dc:date>2024-03-13T14:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying the record with the earliest date.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Identifying-the-record-with-the-earliest-date/m-p/920134#M41217</link>
      <description>&lt;P&gt;Thanks Kurt! This works great as well!&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2024 14:26:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Identifying-the-record-with-the-earliest-date/m-p/920134#M41217</guid>
      <dc:creator>Ihsan-Mahdi</dc:creator>
      <dc:date>2024-03-13T14:26:22Z</dc:date>
    </item>
  </channel>
</rss>

