<?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: Delete observations in a group by dates? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-group-by-dates/m-p/723169#M224362</link>
    <description>&lt;P&gt;This seems to work irrespective of the number of events an ID has. Perfect, thank you!&lt;/P&gt;</description>
    <pubDate>Wed, 03 Mar 2021 15:15:45 GMT</pubDate>
    <dc:creator>Doyinsola</dc:creator>
    <dc:date>2021-03-03T15:15:45Z</dc:date>
    <item>
      <title>Delete observations in a group by dates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-group-by-dates/m-p/722953#M224263</link>
      <description>&lt;P&gt;I have the following data:&lt;/P&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data sample;
	input id $ (diagnosis_date) (:mmddyy10.) date_diff1 date_diff2;
	format diagnosis_date date9.;
	datalines;
1 06/23/2007 . .
1 07/06/2007 13 13
1 09/26/2007 95 82
1 10/02/2007 101 6
2 04/07/2007 . .
2 04/28/2007 21 21
2 07/17/2007 100 79
2 08/05/2007 120 20
2 02/22/2008 220 120
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2021-03-02 at 1.41.50 PM.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55364i7DFAC672CB9A2389/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2021-03-02 at 1.41.50 PM.png" alt="Screen Shot 2021-03-02 at 1.41.50 PM.png" /&gt;&lt;/span&gt;&lt;/DIV&gt;
&lt;P&gt;Each row is an event (a disease diagnosis). I would like to keep the row with the index diagnosis and remove events that are&lt;STRONG&gt; within 90 days of the index&lt;/STRONG&gt; and also &lt;STRONG&gt;within 90 days of each other&lt;/STRONG&gt;. I have created two variables to try to help myself with this.date_diff1 is the number of days between the event and the index diagnosis; date_diff2 is the number of days between an event and the previous event before it. This is the dataset I am hoping to end up with.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2021-03-02 at 1.42.24 PM.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55363iF2153600E530A346/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2021-03-02 at 1.42.24 PM.png" alt="Screen Shot 2021-03-02 at 1.42.24 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 19:27:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-group-by-dates/m-p/722953#M224263</guid>
      <dc:creator>Doyinsola</dc:creator>
      <dc:date>2021-03-02T19:27:38Z</dc:date>
    </item>
    <item>
      <title>Re: Delete observations in a group by dates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-group-by-dates/m-p/722998#M224282</link>
      <description>&lt;P&gt;I would word my solution, which is what I think you mean, like this .&amp;nbsp; This &lt;SPAN&gt;removes "events that are&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;STRONG&gt;within 90 days of the index&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;and &lt;EM&gt;&lt;U&gt;then&lt;/U&gt;&lt;/EM&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;within 90 days of each other, &lt;/STRONG&gt;&lt;EM&gt;&lt;U&gt;thereafter&lt;/U&gt;&lt;/EM&gt;&lt;SPAN&gt;."&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;A SAS loop like this is called a "Do-Witlock" loop.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  do until (last.ID);
    set sample ;
      by ID diagnosis_date;
    if first.ID 
      then _next_date=diagnosis_date;
    if _next_date&amp;lt;=diagnosis_date then do;
      output;
      _next_date=diagnosis_date+89;
    end;
  end;
  drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Mar 2021 21:50:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-group-by-dates/m-p/722998#M224282</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2021-03-02T21:50:48Z</dc:date>
    </item>
    <item>
      <title>Re: Delete observations in a group by dates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-group-by-dates/m-p/723057#M224318</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT; 
  set SAMPLE;
  by ID;
  retain REF_DATE;
  if first.ID | (ID=lag(ID) and DIAGNOSIS_DATE-REF_DATE &amp;gt; 90) then do;
    output;
    REF_DATE=DIAGNOSIS_DATE;
  end;
run;&lt;/CODE&gt;&lt;A style="font-family: inherit; font-size: 16px; white-space: normal;" name="IDX" target="_blank"&gt;&lt;/A&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.WANT" width="313px" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l header" scope="col" width="40px"&gt;ID&lt;/TH&gt;
&lt;TH class="r header" scope="col" width="114px"&gt;DIAGNOSIS_DATE&lt;/TH&gt;
&lt;TH class="r header" scope="col" width="79px"&gt;DATE_DIFF1&lt;/TH&gt;
&lt;TH class="r header" scope="col" width="79px"&gt;DATE_DIFF2&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="40px" class="l data"&gt;1&lt;/TD&gt;
&lt;TD width="114px" class="r data"&gt;23JUN2007&lt;/TD&gt;
&lt;TD width="79px" class="r data"&gt;.&lt;/TD&gt;
&lt;TD width="79px" class="r data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="40px" class="l data"&gt;1&lt;/TD&gt;
&lt;TD width="114px" class="r data"&gt;26SEP2007&lt;/TD&gt;
&lt;TD width="79px" class="r data"&gt;95&lt;/TD&gt;
&lt;TD width="79px" class="r data"&gt;82&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="40px" class="l data"&gt;2&lt;/TD&gt;
&lt;TD width="114px" class="r data"&gt;07APR2007&lt;/TD&gt;
&lt;TD width="79px" class="r data"&gt;.&lt;/TD&gt;
&lt;TD width="79px" class="r data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="40px" class="l data"&gt;2&lt;/TD&gt;
&lt;TD width="114px" class="r data"&gt;17JUL2007&lt;/TD&gt;
&lt;TD width="79px" class="r data"&gt;100&lt;/TD&gt;
&lt;TD width="79px" class="r data"&gt;79&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="40px" class="l data"&gt;2&lt;/TD&gt;
&lt;TD width="114px" class="r data"&gt;22FEB2008&lt;/TD&gt;
&lt;TD width="79px" class="r data"&gt;220&lt;/TD&gt;
&lt;TD width="79px" class="r data"&gt;120&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="branch"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="branch"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Mar 2021 02:13:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-group-by-dates/m-p/723057#M224318</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-03-03T02:13:09Z</dc:date>
    </item>
    <item>
      <title>Re: Delete observations in a group by dates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-group-by-dates/m-p/723169#M224362</link>
      <description>&lt;P&gt;This seems to work irrespective of the number of events an ID has. Perfect, thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 03 Mar 2021 15:15:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-observations-in-a-group-by-dates/m-p/723169#M224362</guid>
      <dc:creator>Doyinsola</dc:creator>
      <dc:date>2021-03-03T15:15:45Z</dc:date>
    </item>
  </channel>
</rss>

