<?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: How do I delete observations with dates occurring within another date for the same ID? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-delete-observations-with-dates-occurring-within-another/m-p/987080#M380032</link>
    <description>&lt;P&gt;If you know which records are the real ones why not just keep those?&lt;/P&gt;
&lt;P&gt;I think the test is just to eliminate those that fall completely within a longer stay.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ID (AdmitDate DischargeDate) (:mmddyy.);
  format AdmitDate DischargeDate yymmdd10.;
cards;
1 1/1/2025  2/4/2025
1 1/3/2025  1/3/2025
1 1/17/2025 1/17/2025
2 3/4/2025  3/4/2025
3 6/7/2025  6/9/2025
3 6/8/2025  6/8/2025
;

proc print;
run;

proc sql;
create table want as 
select * from have
except 
  (select a.* from have a 
   full join have b 
   on a.id=b.id
   and (a.AdmitDate ne b.AdmitDate or a.DischargeDate ne B.DischargeDate)
   where a.AdmitDate between b.AdmitDate and B.DischargeDate
   and a.DischargeDate between b.AdmitDate and B.DischargeDate
   )
;
quit;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But if this is claims data (or direct hospital records) then you probably cannot assume that there exists a single record with the FULL length of stay.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 01 May 2026 16:34:34 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2026-05-01T16:34:34Z</dc:date>
    <item>
      <title>How do I delete observations with dates occurring within another date for the same ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-delete-observations-with-dates-occurring-within-another/m-p/987030#M380021</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;I am working with a healthcare dataset looking at hospital inpatient stays. I am working on cleaning and deduplicating this dataset but run into an issue where I have some stays that occur during another longer stay for the same case. For the analysis I want to do I only want to include the initial stay and not the stays that occur within. Is there a way to either label or delete these stays that occur within a longer stay? I appreciate any help I can get. Thank you! Example below:&lt;/P&gt;&lt;P&gt;This is what my data looks like:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;AdmitDate&lt;/TD&gt;&lt;TD&gt;DischargeDate&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1/1/2025&lt;/TD&gt;&lt;TD&gt;2/4/2025&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1/3/2025&lt;/TD&gt;&lt;TD&gt;1/3/2025&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1/17/2025&lt;/TD&gt;&lt;TD&gt;1/17/2025&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;3/4/2025&lt;/TD&gt;&lt;TD&gt;3/4/2025&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;6/7/2025&lt;/TD&gt;&lt;TD&gt;6/9/2025&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;6/8/2025&lt;/TD&gt;&lt;TD&gt;6/8/2025&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And this is what I would ultimately like:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;AdmitDate&lt;/TD&gt;&lt;TD&gt;DischargeDate&lt;/TD&gt;&lt;TD&gt;Delete&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1/1/2025&lt;/TD&gt;&lt;TD&gt;2/4/2025&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1/3/2025&lt;/TD&gt;&lt;TD&gt;1/3/2025&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1/17/2025&lt;/TD&gt;&lt;TD&gt;1/17/2025&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;3/4/2025&lt;/TD&gt;&lt;TD&gt;3/4/2025&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;6/7/2025&lt;/TD&gt;&lt;TD&gt;6/9/2025&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;6/8/2025&lt;/TD&gt;&lt;TD&gt;6/8/2025&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Thu, 30 Apr 2026 19:39:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-delete-observations-with-dates-occurring-within-another/m-p/987030#M380021</guid>
      <dc:creator>aokolo</dc:creator>
      <dc:date>2026-04-30T19:39:35Z</dc:date>
    </item>
    <item>
      <title>Re: How do I delete observations with dates occurring within another date for the same ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-delete-observations-with-dates-occurring-within-another/m-p/987046#M380022</link>
      <description>&lt;P&gt;Dealing with such overlapping intervals you may have to provide some additional rules. Such as this case where a second starts within another interval but extends past the discharge of a previous interval.&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;ID&lt;/TD&gt;
&lt;TD&gt;AdmitDate&lt;/TD&gt;
&lt;TD&gt;DischargeDate&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;1/1/2025&lt;/TD&gt;
&lt;TD&gt;2/4/2025&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;1/17/2025&lt;/TD&gt;
&lt;TD&gt;3/23/2025&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;What would you do in this case?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If, and this is a pretty big if in some situations you actually do only want the "initial", defined as the earliest admit date then on approach might be to sort but ID and Admit date.&lt;/P&gt;
&lt;P&gt;Then with the sorted data you might be able to use something like this:&lt;/P&gt;
&lt;PRE&gt;Data want;
   set datasorted;
   by id admitdate;
   if first.id;
run;&lt;/PRE&gt;
&lt;P&gt;If the data is sorted by id and admitdate, assumes admitdate is a SAS date value numeric and hopefully with a date type format applied. The BY statement creates automatic variables for each variable that are referenced as First.variablename or Last.variable which are numeric 1/0 valued variables that SAS will treat as true/false to test if a value is the first or last of a given by group. So the IF First.ID, a subsetting IF, keeps only the observations with the first occurrence of an ID value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However the above likely will not work if there are multiple admit sets, such as ID 1 having another admit 05/05/2025.&amp;nbsp; &amp;nbsp;So a more complete description of likely scenarios and a few more rules are needed.&lt;/P&gt;</description>
      <pubDate>Fri, 01 May 2026 01:58:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-delete-observations-with-dates-occurring-within-another/m-p/987046#M380022</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2026-05-01T01:58:11Z</dc:date>
    </item>
    <item>
      <title>Re: How do I delete observations with dates occurring within another date for the same ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-delete-observations-with-dates-occurring-within-another/m-p/987047#M380023</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
input ID	(AdmitDate	DischargeDate) (: mmddyy10.);
format AdmitDate	DischargeDate mmddyy10.;
cards;
1	1/1/2025	2/4/2025
1	1/3/2025	1/3/2025
1	1/17/2025	1/17/2025
2	3/4/2025	3/4/2025
3	6/7/2025	6/9/2025
3	6/8/2025	6/8/2025
;

data temp;
 set have;
 do date=AdmitDate	to DischargeDate;
  output;
 end;
 keep id date;
 format date mmddyy10.;
run;
proc sort data=temp nodupkey;
by id date;
run;
data temp2;
 set temp;
 by id;
 if first.id or dif(date) ne 1 then group+1;
run;
proc summary data=temp2;
by id group;
var date;
output out=want(drop=_: group) min=AdmitDate max=DischargeDate ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 May 2026 02:05:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-delete-observations-with-dates-occurring-within-another/m-p/987047#M380023</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2026-05-01T02:05:13Z</dc:date>
    </item>
    <item>
      <title>Re: How do I delete observations with dates occurring within another date for the same ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-delete-observations-with-dates-occurring-within-another/m-p/987049#M380024</link>
      <description>&lt;P&gt;You can perform that algorithm in a single pass (or two passes if you need to first calculate a reasonable MIN/MAX values for the date ranges).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First let's make some data that has non nested intervals and also multiple intervals for the same ID.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ID (AdmitDate DischargeDate) (:mmddyy.);
  format AdmitDate  DischargeDate yymmdd10.;
cards;
1 1/1/2025  2/4/2025
1 1/3/2025  1/3/2025
1 1/17/2025 1/17/2025
2 3/4/2025  3/4/2025
3 6/7/2025  6/9/2025
3 6/8/2025  6/8/2025
4 1/1/2025  2/4/2025
4 1/17/2025 3/23/2025
5 1/1/2025  2/4/2025
5 3/1/2025  4/1/2025
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now let's find the min and&amp;nbsp; max dates to help set the possible date range.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select min(min(AdmitDate,DischargeDate))
     , max(max(AdmitDate,DischargeDate))
  into :mind trimmed
     , :maxd trimmed
  from have
;
quit;
%let length=%eval(&amp;amp;maxd-&amp;amp;mind+1);
%put &amp;amp;=length (From %sysfunc(putn(&amp;amp;mind,yymmdd10.)) to %sysfunc(putn(&amp;amp;maxd,yymmdd10.)));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can skip this step if you already know what values to use for MIND and LENGTH.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now for each subject use your DAY loop to flag those days and then find the begin/end of each set of flagged days.&lt;/P&gt;
&lt;P&gt;Here is an example using a simple character variable.&amp;nbsp; Doing this makes it easy to use the CALL SCAN routine to find the periods.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data periods ;
  length days $&amp;amp;length.;
  do until(last.id);
    set have;
    by id;
    do day=admitdate to dischargedate;
      substr(days,day-&amp;amp;mind.+1,1)='1';
    end;
  end;
  period=1;
  position=1;
  do until(position=0);
    call scan(days,period,position,length,' ');   
    if position then do;
      AdmitDate = &amp;amp;mind.+position-1;
      DischargeDate = AdmitDate + length -1 ;
    end;
    if position or period=1 then output;
    period+1;
  end;
  drop days day position length ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2026-04-30 at 11.13.41 PM.png" style="width: 570px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/114577i7592AFDF04F09501/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2026-04-30 at 11.13.41 PM.png" alt="Screenshot 2026-04-30 at 11.13.41 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Note this could get slow if the range of dates is very long since SAS processes very long character variables slowly.&amp;nbsp;&lt;/STRONG&gt; &lt;/EM&gt;In that case you should probably use an ARRAY instead a character variable. You could use some DO loops to find the periods of flagged days instead of the CALL SCAN method.&lt;/P&gt;</description>
      <pubDate>Fri, 01 May 2026 03:19:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-delete-observations-with-dates-occurring-within-another/m-p/987049#M380024</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2026-05-01T03:19:19Z</dc:date>
    </item>
    <item>
      <title>Re: How do I delete observations with dates occurring within another date for the same ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-delete-observations-with-dates-occurring-within-another/m-p/987053#M380025</link>
      <description>&lt;P&gt;Thank you for taking the time to respond to my question. In response to your example of date overlap, we would conduct a manual review to see what is going on with these two admissions, then decide which one to remove. What is happening in this dataset is there are claims that occur during an inpatient stay (for procedures, services, etc) and those are given different lines in the data on the day that they occur within the inpatient stay. Since we only want to count the inpatient stays and we're not yet looking at services, I wanted a way to flag and remove those lines. And you're correct, the same ID could have multiple inpatient stays that we would want to count so sorting by ID and admitdate would remove other inpatient stays we'd need.&lt;/P&gt;</description>
      <pubDate>Fri, 01 May 2026 13:03:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-delete-observations-with-dates-occurring-within-another/m-p/987053#M380025</guid>
      <dc:creator>aokolo</dc:creator>
      <dc:date>2026-05-01T13:03:40Z</dc:date>
    </item>
    <item>
      <title>Re: How do I delete observations with dates occurring within another date for the same ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-delete-observations-with-dates-occurring-within-another/m-p/987054#M380026</link>
      <description>&lt;P&gt;Tom,&lt;BR /&gt;I just want to keep my code simple and readable.&lt;BR /&gt;I really don't care about the code is long or short . &lt;BR /&gt;I think the short code would bring side effect . The readable code is the most important thing.&lt;/P&gt;</description>
      <pubDate>Fri, 01 May 2026 13:21:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-delete-observations-with-dates-occurring-within-another/m-p/987054#M380026</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2026-05-01T13:21:16Z</dc:date>
    </item>
    <item>
      <title>Re: How do I delete observations with dates occurring within another date for the same ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-delete-observations-with-dates-occurring-within-another/m-p/987061#M380027</link>
      <description>Thank you so much! Question, if this is allowed, if I wanted to keep dates that are the same as the admit date and just remove those that occur within the date window, how would I change this code to reflect that? I tried your code on my dataset and it worked but it also ended up removing ED visits that happened on the same day and resulted in the inpatient stay and I would like to keep those.</description>
      <pubDate>Fri, 01 May 2026 14:35:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-delete-observations-with-dates-occurring-within-another/m-p/987061#M380027</guid>
      <dc:creator>aokolo</dc:creator>
      <dc:date>2026-05-01T14:35:57Z</dc:date>
    </item>
    <item>
      <title>Re: How do I delete observations with dates occurring within another date for the same ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-delete-observations-with-dates-occurring-within-another/m-p/987079#M380031</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Tom,&lt;BR /&gt;I just want to keep my code simple and readable.&lt;BR /&gt;I really don't care about the code is long or short . &lt;BR /&gt;I think the short code would bring side effect . The readable code is the most important thing.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The point was not readability, but performance.&amp;nbsp; Your code made multiple passes through the data.&lt;/P&gt;</description>
      <pubDate>Fri, 01 May 2026 16:23:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-delete-observations-with-dates-occurring-within-another/m-p/987079#M380031</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2026-05-01T16:23:31Z</dc:date>
    </item>
    <item>
      <title>Re: How do I delete observations with dates occurring within another date for the same ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-delete-observations-with-dates-occurring-within-another/m-p/987080#M380032</link>
      <description>&lt;P&gt;If you know which records are the real ones why not just keep those?&lt;/P&gt;
&lt;P&gt;I think the test is just to eliminate those that fall completely within a longer stay.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ID (AdmitDate DischargeDate) (:mmddyy.);
  format AdmitDate DischargeDate yymmdd10.;
cards;
1 1/1/2025  2/4/2025
1 1/3/2025  1/3/2025
1 1/17/2025 1/17/2025
2 3/4/2025  3/4/2025
3 6/7/2025  6/9/2025
3 6/8/2025  6/8/2025
;

proc print;
run;

proc sql;
create table want as 
select * from have
except 
  (select a.* from have a 
   full join have b 
   on a.id=b.id
   and (a.AdmitDate ne b.AdmitDate or a.DischargeDate ne B.DischargeDate)
   where a.AdmitDate between b.AdmitDate and B.DischargeDate
   and a.DischargeDate between b.AdmitDate and B.DischargeDate
   )
;
quit;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But if this is claims data (or direct hospital records) then you probably cannot assume that there exists a single record with the FULL length of stay.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 May 2026 16:34:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-delete-observations-with-dates-occurring-within-another/m-p/987080#M380032</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2026-05-01T16:34:34Z</dc:date>
    </item>
    <item>
      <title>Re: How do I delete observations with dates occurring within another date for the same ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-delete-observations-with-dates-occurring-within-another/m-p/987095#M380036</link>
      <description>Tom,&lt;BR /&gt;As I said , the most important thing I care about is readable for code, not length, not performance . not others ....&lt;BR /&gt;Unless the running time of code is WAY too much I can't accept, in that case I would consider about enhancing  the performance of code . &lt;BR /&gt;Your code is not easy to read than mine, don't you think so ?</description>
      <pubDate>Sat, 02 May 2026 01:39:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-delete-observations-with-dates-occurring-within-another/m-p/987095#M380036</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2026-05-02T01:39:01Z</dc:date>
    </item>
    <item>
      <title>Re: How do I delete observations with dates occurring within another date for the same ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-delete-observations-with-dates-occurring-within-another/m-p/987096#M380037</link>
      <description>&lt;P&gt;You want to keep the obs which have the same&amp;nbsp;&lt;STRONG&gt;AdmitDate&lt;/STRONG&gt;?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
infile cards truncover;
input ID	(AdmitDate	DischargeDate) (: mmddyy10.);
format AdmitDate	DischargeDate mmddyy10.;
cards;
&lt;STRONG&gt;1	1/1/2025	2/4/2025
1	1/1/2025	4/4/2025&lt;/STRONG&gt;
1	1/3/2025	1/3/2025
1	1/17/2025	1/17/2025
2	3/4/2025	3/4/2025
3	6/7/2025	6/9/2025
3	6/8/2025	6/8/2025
;
/*keep dates that are the same as the admit date*/
proc sql;
create table dup as
select * from have 
 group by id,AdmitDate
  having count(*)&amp;gt;1;
quit;


data temp;
 set have;
 do date=AdmitDate	to DischargeDate;
  output;
 end;
 keep id date;
 format date mmddyy10.;
run;
proc sort data=temp nodupkey;
by id date;
run;
data temp2;
 set temp;
 by id;
 if first.id or dif(date) ne 1 then group+1;
run;
proc summary data=temp2;
by id group;
var date;
output out=temp3(drop=_: group) min=AdmitDate max=DischargeDate ;
run;


/*combine them together*/
proc sql;
create table want as
select * from dup
union
select * from temp3;
quit;&lt;/PRE&gt;</description>
      <pubDate>Sat, 02 May 2026 01:57:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-delete-observations-with-dates-occurring-within-another/m-p/987096#M380037</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2026-05-02T01:57:50Z</dc:date>
    </item>
  </channel>
</rss>

