<?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 Removing a row of data if the range of the dates fall within the larger range in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Removing-a-row-of-data-if-the-range-of-the-dates-fall-within-the/m-p/609857#M17991</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data set that looks like this:&lt;BR /&gt;&lt;BR /&gt;ID &amp;nbsp;&amp;nbsp; Start_Date &amp;nbsp;&amp;nbsp; End_Date &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp;&amp;nbsp; 01/01/2018 &amp;nbsp; 01/01/2018&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp;&amp;nbsp; 01/07/2017 &amp;nbsp; 30/06/2018&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp;&amp;nbsp; 01/07/2017 &amp;nbsp; 21/03/2018&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp;&amp;nbsp; 01/09/2017 &amp;nbsp; 26/10/2017&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp;&amp;nbsp; 03/10/2017 &amp;nbsp; 31/12/2017&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp;&amp;nbsp; 01/04/2018 &amp;nbsp; 19/06/2018&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was wanting to remove the rows of data if the range of the dates fall within the larger range, so output from above will look like this:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp;&amp;nbsp; Start_Date &amp;nbsp;&amp;nbsp; End_Date &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp;&amp;nbsp; 01/07/2017 &amp;nbsp; 30/06/2018&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp;&amp;nbsp; 01/07/2017 &amp;nbsp; 21/03/2018&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp;&amp;nbsp; 01/04/2018 &amp;nbsp; 19/06/2018&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help appreciated &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Thank you!&lt;/P&gt;</description>
    <pubDate>Fri, 06 Dec 2019 04:38:53 GMT</pubDate>
    <dc:creator>Bounce</dc:creator>
    <dc:date>2019-12-06T04:38:53Z</dc:date>
    <item>
      <title>Removing a row of data if the range of the dates fall within the larger range</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Removing-a-row-of-data-if-the-range-of-the-dates-fall-within-the/m-p/609857#M17991</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data set that looks like this:&lt;BR /&gt;&lt;BR /&gt;ID &amp;nbsp;&amp;nbsp; Start_Date &amp;nbsp;&amp;nbsp; End_Date &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp;&amp;nbsp; 01/01/2018 &amp;nbsp; 01/01/2018&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp;&amp;nbsp; 01/07/2017 &amp;nbsp; 30/06/2018&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp;&amp;nbsp; 01/07/2017 &amp;nbsp; 21/03/2018&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp;&amp;nbsp; 01/09/2017 &amp;nbsp; 26/10/2017&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp;&amp;nbsp; 03/10/2017 &amp;nbsp; 31/12/2017&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp;&amp;nbsp; 01/04/2018 &amp;nbsp; 19/06/2018&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was wanting to remove the rows of data if the range of the dates fall within the larger range, so output from above will look like this:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp;&amp;nbsp; Start_Date &amp;nbsp;&amp;nbsp; End_Date &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp;&amp;nbsp; 01/07/2017 &amp;nbsp; 30/06/2018&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp;&amp;nbsp; 01/07/2017 &amp;nbsp; 21/03/2018&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp;&amp;nbsp; 01/04/2018 &amp;nbsp; 19/06/2018&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help appreciated &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 06 Dec 2019 04:38:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Removing-a-row-of-data-if-the-range-of-the-dates-fall-within-the/m-p/609857#M17991</guid>
      <dc:creator>Bounce</dc:creator>
      <dc:date>2019-12-06T04:38:53Z</dc:date>
    </item>
    <item>
      <title>Re: Removing a row of data if the range of the dates fall within the larger range</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Removing-a-row-of-data-if-the-range-of-the-dates-fall-within-the/m-p/609860#M17992</link>
      <description>&lt;P&gt;Could you please suggest the range , as per the code below you can get the difference between the dates as below&lt;/P&gt;
&lt;P&gt;if you know the range then you can output the rows as per diff.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;     
input ID    Start_Date:ddmmyy10.    End_Date :ddmmyy10. ;
diff=End_Date-Start_Date;
format Start_Date End_Date date9.;
cards;   
1 01/01/2018 01/01/2018 
1 01/07/2017 30/06/2018
2 01/07/2017 21/03/2018
2 01/09/2017 26/10/2017
2 03/10/2017 31/12/2017
2 01/04/2018 19/06/2018
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 431px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34488iE236A9C07FE571BF/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Dec 2019 05:23:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Removing-a-row-of-data-if-the-range-of-the-dates-fall-within-the/m-p/609860#M17992</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-12-06T05:23:40Z</dc:date>
    </item>
    <item>
      <title>Re: Removing a row of data if the range of the dates fall within the larger range</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Removing-a-row-of-data-if-the-range-of-the-dates-fall-within-the/m-p/609862#M17993</link>
      <description>&lt;P&gt;The range of the dates will always between 01/07/2017 and 30/06/2018.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But the start_date and end_date will fluctuate as many as 10 times per ID with overlapping ranges.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have actually calculated the diff column in the exact same way you have (except I include the last day too). But I trying to find the total number of days for that ID within the start and end date. As you can see, the overlapping dates will produce incorrect results if I simply sum them all now.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hence I will need to remove the ones that are within the other dates before summing them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Eg: for ID 1, the total sum is 365 days (01/07/2017 - 30/06/2018) and ID 2, it will be 344 (01/07/2017 - 21/03/2018) + (01/04/2018 - 19/06/2018).&lt;/P&gt;</description>
      <pubDate>Fri, 06 Dec 2019 05:31:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Removing-a-row-of-data-if-the-range-of-the-dates-fall-within-the/m-p/609862#M17993</guid>
      <dc:creator>Bounce</dc:creator>
      <dc:date>2019-12-06T05:31:43Z</dc:date>
    </item>
    <item>
      <title>Re: Removing a row of data if the range of the dates fall within the larger range</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Removing-a-row-of-data-if-the-range-of-the-dates-fall-within-the/m-p/609864#M17994</link>
      <description>&lt;P&gt;please try the below code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;     
input ID    Start_Date:ddmmyy10.    End_Date :ddmmyy10. ;
diff=End_Date-Start_Date;
format Start_Date End_Date date9.;
cards;   
1 01/01/2018 01/01/2018 
1 01/07/2017 30/06/2018
2 01/07/2017 21/03/2018
2 01/09/2017 26/10/2017
2 03/10/2017 31/12/2017
2 01/04/2018 19/06/2018
;
proc sort data=have;
by id descending diff;
run;

data want;
set have;
by id descending diff;
retain Start_Date2 End_Date2 ;
if first.id then do;
Start_Date2=Start_Date;
End_Date2=End_Date;
end;
if Start_Date2&amp;lt;=Start_Date&amp;lt;=End_Date2 then flag1=1;
if Start_Date2&amp;lt;=End_Date&amp;lt;=End_Date2 then flag1=1;
if first.id or flag1=.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Dec 2019 05:48:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Removing-a-row-of-data-if-the-range-of-the-dates-fall-within-the/m-p/609864#M17994</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-12-06T05:48:36Z</dc:date>
    </item>
    <item>
      <title>Re: Removing a row of data if the range of the dates fall within the larger range</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Removing-a-row-of-data-if-the-range-of-the-dates-fall-within-the/m-p/609914#M18002</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;     
input ID    Start_Date:ddmmyy10.    End_Date :ddmmyy10. ;
format Start_Date End_Date date9.;
cards;   
1 01/01/2018 01/01/2018 
1 01/07/2017 30/06/2018
2 01/07/2017 21/03/2018
2 01/09/2017 26/10/2017
2 03/10/2017 31/12/2017
2 01/04/2018 19/06/2018
;

data temp;
 set have;
 do date= Start_Date to End_Date;
  output;
 end;
 drop  Start_Date  End_Date;
 format date ddmmyy10.;
 run;
 proc sort data=temp nodupkey;
 by id date;
 run;
 data temp;
  set temp;
  by id;
  if first.id or dif(date) ne 1 then group+1;
run;
proc summary data=temp ;
by id group;
var date;
output out=want(drop=_:) min=start_date max=end_date;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;P.S. If you have a big table, try split it into many small tables and run this code on each small table.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Dec 2019 11:38:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Removing-a-row-of-data-if-the-range-of-the-dates-fall-within-the/m-p/609914#M18002</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-12-06T11:38:30Z</dc:date>
    </item>
    <item>
      <title>Re: Removing a row of data if the range of the dates fall within the larger range</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Removing-a-row-of-data-if-the-range-of-the-dates-fall-within-the/m-p/609918#M18003</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/267739"&gt;@Bounce&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have overlapping ranges, you can try the following code, which will retrieve the min(start_date) and the max(end_date) if the lag is strictly more than 1.&lt;/P&gt;
&lt;P&gt;PS: I have deliberately modified the entry data to show different cases.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My best,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input ID Start_Date End_Date;
	informat Start_Date End_Date ddmmyy10.;
	format Start_Date End_Date date9.;
	cards;
1 01/01/2019 04/01/2019 &lt;BR /&gt;1 07/01/2019 12/01/2019&lt;BR /&gt;1 10/01/2019 18/01/2019&lt;BR /&gt;1 14/01/2019 16/01/2019&lt;BR /&gt;1 16/01/2019 22/01/2019&lt;BR /&gt;2 01/01/2019 04/01/2019 &lt;BR /&gt;2 07/01/2019 12/01/2019&lt;BR /&gt;2 10/01/2019 18/01/2019
;
run;

proc sort data=have;
	by ID Start_Date End_Date;
run;

data have2;
	set have;
	format _lag date9.;
	by ID;
	_lag = lag(End_Date) ;
	if first.ID then do;
			_lag = .;
			flag = 0;
		end;
	if _lag + 1 &amp;lt; Start_Date  then flag + 1;
run;

proc sql;
	create table want as 
	select 	ID,
			min(Start_Date) as Start_date format=date9.,
			max(End_date) as End_date format=date9.
	from have2
	group by ID, flag;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Dec 2019 11:54:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Removing-a-row-of-data-if-the-range-of-the-dates-fall-within-the/m-p/609918#M18003</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2019-12-06T11:54:49Z</dc:date>
    </item>
  </channel>
</rss>

