<?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: Remove Duplicates First. and Last. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Remove-Duplicates-First-and-Last/m-p/563872#M158111</link>
    <description>&lt;P&gt;or simply the proc sort also works&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=want nodupkey;
by Customer_ID Transaction_ID ;
run;
&lt;/CODE&gt;&amp;nbsp; &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 05 Jun 2019 20:05:26 GMT</pubDate>
    <dc:creator>Jagadishkatam</dc:creator>
    <dc:date>2019-06-05T20:05:26Z</dc:date>
    <item>
      <title>Remove Duplicates First. and Last.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-Duplicates-First-and-Last/m-p/563856#M158102</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am looking for code to remove duplicate records with overlapping dates for same customer ID and keep the one with oldest Service_Date_From.&lt;/P&gt;&lt;P&gt;For e.g. If a customer has Service_Date_From as 10/04/18 and Service_Date_To as 10/12/18 then any other transaction of the same customer between these 2 dates mentioned above (be it Service_From_Date or Service_To_Date) should be considered as duplicate and hence dropped from the output data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone please help with the code.&lt;BR /&gt;Preferably using the first. and last. options&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;infile datalines dlm='09'x dsd;&lt;BR /&gt;input Customer_ID $ Transaction_ID Service_Date_From mmddyy8 Service_Date_To mmddyy8.;&lt;BR /&gt;format Service_Date_From mmddyy10.;&lt;BR /&gt;datalines;&lt;BR /&gt;AB1 12345 10/12/18 10/14/18&lt;BR /&gt;AB1 12345 10/14/18 10/18/18&lt;BR /&gt;AB1 12345 10/15/18 10/16/18&lt;BR /&gt;AB2 22233 6/10/18 06/15/18&lt;BR /&gt;AB2 22234 9/12/18 9/13/18&lt;BR /&gt;AB3 35678 1/5/19 1/15/19&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;Result I want is this.&lt;/P&gt;&lt;P&gt;AB1 12345 10/12/18 10/14/18&lt;BR /&gt;AB2 22233 6/10/18 06/15/18&lt;BR /&gt;AB2 22234 9/12/18 9/13/18&lt;BR /&gt;AB3 35678 1/5/19 1/15/19&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2019 20:21:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-Duplicates-First-and-Last/m-p/563856#M158102</guid>
      <dc:creator>VarunD</dc:creator>
      <dc:date>2019-06-05T20:21:49Z</dc:date>
    </item>
    <item>
      <title>Re: Remove Duplicates First. and Last.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-Duplicates-First-and-Last/m-p/563868#M158109</link>
      <description>&lt;P&gt;Please try the&amp;nbsp; first.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dlm='09'x dsd;
input Customer_ID $ Transaction_ID Service_Date_From mmddyy8 Service_Date_To mmddyy8.;
format Service_Date_From mmddyy10.;
datalines;
AB1 12345 10/12/18 10/14/18
AB1 12346 10/14/18 10/18/18
AB1 12347 10/15/18 10/16/18
AB2 22233 6/10/18 06/15/18
AB2 22234 9/12/18 9/13/18
AB3 35678 1/5/19 1/15/19
;
run;

proc sort data=have;
by  Customer_ID $ Transaction_ID Service_Date_From;
run;

data want;
set have;
by  Customer_ID $ Transaction_ID Service_Date_From;
if first.Transaction_ID;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Jun 2019 20:02:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-Duplicates-First-and-Last/m-p/563868#M158109</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-06-05T20:02:43Z</dc:date>
    </item>
    <item>
      <title>Re: Remove Duplicates First. and Last.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-Duplicates-First-and-Last/m-p/563872#M158111</link>
      <description>&lt;P&gt;or simply the proc sort also works&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=want nodupkey;
by Customer_ID Transaction_ID ;
run;
&lt;/CODE&gt;&amp;nbsp; &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2019 20:05:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-Duplicates-First-and-Last/m-p/563872#M158111</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-06-05T20:05:26Z</dc:date>
    </item>
    <item>
      <title>Re: Remove Duplicates First. and Last.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-Duplicates-First-and-Last/m-p/563879#M158114</link>
      <description>I am sorry that didn't seem to work. I guess there is drawback with the data I provided as well. Because Transaction ID is not unique. I will update the data now .</description>
      <pubDate>Wed, 05 Jun 2019 20:19:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-Duplicates-First-and-Last/m-p/563879#M158114</guid>
      <dc:creator>VarunD</dc:creator>
      <dc:date>2019-06-05T20:19:50Z</dc:date>
    </item>
    <item>
      <title>Re: Remove Duplicates First. and Last.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-Duplicates-First-and-Last/m-p/563951#M158145</link>
      <description>&lt;P&gt;Why do you only keep one record for AB1?&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;AB1 12345 10/12/18 10/14/18&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2019 03:27:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-Duplicates-First-and-Last/m-p/563951#M158145</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-06-06T03:27:42Z</dc:date>
    </item>
    <item>
      <title>Re: Remove Duplicates First. and Last.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-Duplicates-First-and-Last/m-p/564064#M158188</link>
      <description>&lt;P&gt;For the first record of AB1 , the service_date_to has 10/14 which overlaps with second record's service date from. Similarly, 2nd record has dates 10/14 to 10/18 which overlaps with 3rd record dates i.e. 10/15 and 10/16. I retain first record since it has the oldest date i.e. 10/12. I hope that answers your question. Let me know if you need more info on this. Thanks for looking into it.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2019 12:59:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-Duplicates-First-and-Last/m-p/564064#M158188</guid>
      <dc:creator>VarunD</dc:creator>
      <dc:date>2019-06-06T12:59:40Z</dc:date>
    </item>
    <item>
      <title>Re: Remove Duplicates First. and Last.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-Duplicates-First-and-Last/m-p/564079#M158192</link>
      <description>As per his Source data , and date guidelines, its not matching, kindly provide correct data</description>
      <pubDate>Thu, 06 Jun 2019 13:20:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-Duplicates-First-and-Last/m-p/564079#M158192</guid>
      <dc:creator>Riteshdell</dc:creator>
      <dc:date>2019-06-06T13:20:53Z</dc:date>
    </item>
    <item>
      <title>Re: Remove Duplicates First. and Last.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-Duplicates-First-and-Last/m-p/564198#M158229</link>
      <description>Thanks for looking into this. Could you please specify what is wrong with the data ?</description>
      <pubDate>Thu, 06 Jun 2019 16:39:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-Duplicates-First-and-Last/m-p/564198#M158229</guid>
      <dc:creator>VarunD</dc:creator>
      <dc:date>2019-06-06T16:39:45Z</dc:date>
    </item>
    <item>
      <title>Re: Remove Duplicates First. and Last.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-Duplicates-First-and-Last/m-p/564317#M158274</link>
      <description>&lt;P&gt;2 questions:&lt;BR /&gt;1.If the dates are say:&lt;BR /&gt;Jan01-Jan03&lt;BR /&gt;Jan02-Jan04&lt;BR /&gt;Jan03-Jan05&lt;BR /&gt;Jan04-Jan26&lt;BR /&gt;which records do you keep?&lt;BR /&gt;2.Is the data, sorted i.e. does the first record encountered have any special reason to be kept rather than the second one?&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2019 21:35:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-Duplicates-First-and-Last/m-p/564317#M158274</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-06-06T21:35:15Z</dc:date>
    </item>
    <item>
      <title>Re: Remove Duplicates First. and Last.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-Duplicates-First-and-Last/m-p/564529#M158371</link>
      <description>I would keep Jan01-Jan03 since it has the oldest date i.e. Jan01.&lt;BR /&gt;Data is not sorted. Any record with the oldest date should be kept. Hope that answers your questions. Please let me know if you need more information on this. Again, thanks for looking into this. Have a good weekend !</description>
      <pubDate>Fri, 07 Jun 2019 18:11:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-Duplicates-First-and-Last/m-p/564529#M158371</guid>
      <dc:creator>VarunD</dc:creator>
      <dc:date>2019-06-07T18:11:47Z</dc:date>
    </item>
  </channel>
</rss>

