<?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: Deleting rows if dates are a certain time apart within an ID. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Deleting-rows-if-dates-are-a-certain-time-apart-within-an-ID/m-p/803945#M316574</link>
    <description>Thanks again for the help &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;</description>
    <pubDate>Fri, 25 Mar 2022 00:35:54 GMT</pubDate>
    <dc:creator>Manhort</dc:creator>
    <dc:date>2022-03-25T00:35:54Z</dc:date>
    <item>
      <title>Deleting rows if dates are a certain time apart within an ID.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-rows-if-dates-are-a-certain-time-apart-within-an-ID/m-p/803928#M316569</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to filter repeated measures if the dates (by id) are not 60 days apart. There are hundreds of id's in the dataset; I am showing three here.&lt;/P&gt;&lt;P&gt;Person 1 can be reduced to a single date (because they're the same). Person 2 can be reduced to a single date (I figure choosing the earliest date makes the most sense). Person 3 has 2 dates that are far enough apart to keep, but a third that would cause that row to be dropped (again wanting to keep the earliest date).&amp;nbsp; Dates can be repeated and a person can have any number of dates from 1-10 (although no one has 7-9 oddly enough).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA have;&lt;BR /&gt;input id date mmddyy10.;&lt;BR /&gt;format date mmddyy10.;&lt;BR /&gt;CARDS;&lt;/P&gt;&lt;P&gt;1 2/20/2016&lt;BR /&gt;1 2/20/2016&lt;BR /&gt;2 1/25/2016&lt;BR /&gt;2 1/28/2016&lt;BR /&gt;2 2/4/2016&lt;BR /&gt;2 2/4/2016&lt;BR /&gt;3 3/18/2016&lt;/P&gt;&lt;P&gt;3 3/20/2016&lt;BR /&gt;3 9/6/2016&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA want;&lt;BR /&gt;input id date mmddyy10.;&lt;BR /&gt;format date mmddyy10.;&lt;BR /&gt;CARDS;&lt;/P&gt;&lt;P&gt;1 2/20/2016&lt;BR /&gt;2 1/25/2016&lt;BR /&gt;3 3/18/2016&lt;BR /&gt;3 9/6/2016&lt;/P&gt;&lt;P&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's my logic for comparing dates, and an example of a person with three sorted dates:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Case1:&lt;/P&gt;&lt;P&gt;If date2-date1 &amp;lt;= 60, keep date1 and delete date2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; For the next comparison date1 would be used again.&lt;/P&gt;&lt;P&gt;If date3-date1 &amp;lt;=60, keep date1 delete date3&lt;/P&gt;&lt;P&gt;====================================&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Case2:&lt;/P&gt;&lt;P&gt;If date2-date1 &amp;gt;= 60, keep both dates(rows) &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; At this point, when keeping both dates, the next comparison must be done using the latest date.&lt;/P&gt;&lt;P&gt;If date3-date2 &amp;gt;=60, keep both dates&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; In this situation all three dates are retained. But had date3-date2 been &amp;lt;= 60 I would've dropped date3.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2022 22:50:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-rows-if-dates-are-a-certain-time-apart-within-an-ID/m-p/803928#M316569</guid>
      <dc:creator>Manhort</dc:creator>
      <dc:date>2022-03-24T22:50:55Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting rows if dates are a certain time apart within an ID.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-rows-if-dates-are-a-certain-time-apart-within-an-ID/m-p/803940#M316572</link>
      <description>&lt;P&gt;This is a case where you have to look ahead one observation to see if the upcoming gap is more than 60 days (or if the next observation starts a new id).&amp;nbsp; &amp;nbsp;You can do this via a MERGE statement where you merge observation1 with observation2 (with ID and DATE variables renamed), and then merge observation 2 with observation 3, etc.&amp;nbsp; That is supported via the "FIRSTOBS=2" option in one of the objects of the MERGE statement below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; 

DATA have;
input id date mmddyy10.;
format date mmddyy10.;
CARDS;
1 2/20/2016
1 2/20/2016
2 1/25/2016
2 1/28/2016
2 2/4/2016
2 2/4/2016
3 3/18/2016
3 3/20/2016
3 9/6/2016
;
RUN;

data want (drop=_:);
  do until (_nxt_id^=id or date+60&amp;lt;_nxt_date);
    merge have
          have (firstobs=2 keep=id date rename=(id=_nxt_id date=_nxt_date));
    if _init_date=. then _init_date=date;
  end;
  date=_init_date;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Mar 2022 00:17:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-rows-if-dates-are-a-certain-time-apart-within-an-ID/m-p/803940#M316572</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-03-25T00:17:02Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting rows if dates are a certain time apart within an ID.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Deleting-rows-if-dates-are-a-certain-time-apart-within-an-ID/m-p/803945#M316574</link>
      <description>Thanks again for the help &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;</description>
      <pubDate>Fri, 25 Mar 2022 00:35:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Deleting-rows-if-dates-are-a-certain-time-apart-within-an-ID/m-p/803945#M316574</guid>
      <dc:creator>Manhort</dc:creator>
      <dc:date>2022-03-25T00:35:54Z</dc:date>
    </item>
  </channel>
</rss>

