<?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: Merging two intervals based on a condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merging-two-intervals-based-on-a-condition/m-p/708184#M217578</link>
    <description>&lt;P&gt;That is complicated . There too many scenario you need to consider.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards ;
input ID    (first_Date last_Date) (: mmddyy10.) ;	 
cards;
001 1/1/2004  1/5/2004
001 1/5/2004  1/10/2004
003 1/1/2005  4/5/2009
004 4/4/2010 4/5/2010
004 4/5/2010 4/15/2010
;

data temp;
 set have;
 do date=first_date to last_date;
  output;
 end;
 drop first_date last_date;
run;
proc sort data=temp out=temp1 nodupkey;
by id date;
run;
data temp2;
 set temp1;
 by id;
 if first.id or dif(date) ne 1 then group+1;
run;
data want;
 do until(last.group);
  set temp2;
  by group;
  if first.group then first_date=date;
  if last.group then last_date=date;
 end;
  format first_date last_date mmddyy10.;
drop group date;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 25 Dec 2020 12:33:34 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2020-12-25T12:33:34Z</dc:date>
    <item>
      <title>Merging two intervals based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-two-intervals-based-on-a-condition/m-p/708072#M217520</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards ;
input ID    first_Date last_Date ;	 
cards;
001 1/1/2004  1/5/2004
001 1/5/2004  1/10/2004
003 1/1/2005  4/5/2009
004 4/4/2010 4/5/2010
004 4/5/2010 4/15/2010
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hi everyone, I have the above data, I am trying to merge any intervals when the last date for that id equals the first date of a subsequent interval. For example for id number 1: I want the start date to be 1/1/2004 and the last date to be a/10/2004. Same for id number 4.&amp;nbsp;&lt;/P&gt;&lt;P&gt;output data&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;001 1/1/2004  1/10/2004
003 1/1/2005  4/5/2009
004 4/4/2010 4/15/2010
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Dec 2020 12:44:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-two-intervals-based-on-a-condition/m-p/708072#M217520</guid>
      <dc:creator>lillymaginta1</dc:creator>
      <dc:date>2020-12-24T12:44:45Z</dc:date>
    </item>
    <item>
      <title>Re: Merging two intervals based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-two-intervals-based-on-a-condition/m-p/708075#M217522</link>
      <description>&lt;P&gt;Does it always happen that the first_date of one record is &lt;STRONG&gt;always equal&lt;/STRONG&gt; to the last_date for the previous record, within an ID? Or can there be cases where this is not true, for example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;001 1/1/2004  1/5/2004
001 1/6/2004  1/10/2004&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Dec 2020 13:45:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-two-intervals-based-on-a-condition/m-p/708075#M217522</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-12-24T13:45:23Z</dc:date>
    </item>
    <item>
      <title>Re: Merging two intervals based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-two-intervals-based-on-a-condition/m-p/708089#M217527</link>
      <description>&lt;P&gt;Hi PaigeMiller, yes plenty. But in that case, I want to keep them as-is and only merge the one where the last date equals the first date of a subsequent record within the same ID.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Dec 2020 15:18:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-two-intervals-based-on-a-condition/m-p/708089#M217527</guid>
      <dc:creator>lillymaginta1</dc:creator>
      <dc:date>2020-12-24T15:18:51Z</dc:date>
    </item>
    <item>
      <title>Re: Merging two intervals based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-two-intervals-based-on-a-condition/m-p/708099#M217533</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/69937"&gt;@lillymaginta1&lt;/a&gt;&amp;nbsp; Please post a more comprehensive/representative sample of your HAVE and WANT that covers all your scenarios. Explain your requirements for those. That would help in providing a solution in one shot.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Dec 2020 16:12:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-two-intervals-based-on-a-condition/m-p/708099#M217533</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-12-24T16:12:45Z</dc:date>
    </item>
    <item>
      <title>Re: Merging two intervals based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merging-two-intervals-based-on-a-condition/m-p/708184#M217578</link>
      <description>&lt;P&gt;That is complicated . There too many scenario you need to consider.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards ;
input ID    (first_Date last_Date) (: mmddyy10.) ;	 
cards;
001 1/1/2004  1/5/2004
001 1/5/2004  1/10/2004
003 1/1/2005  4/5/2009
004 4/4/2010 4/5/2010
004 4/5/2010 4/15/2010
;

data temp;
 set have;
 do date=first_date to last_date;
  output;
 end;
 drop first_date last_date;
run;
proc sort data=temp out=temp1 nodupkey;
by id date;
run;
data temp2;
 set temp1;
 by id;
 if first.id or dif(date) ne 1 then group+1;
run;
data want;
 do until(last.group);
  set temp2;
  by group;
  if first.group then first_date=date;
  if last.group then last_date=date;
 end;
  format first_date last_date mmddyy10.;
drop group date;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Dec 2020 12:33:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merging-two-intervals-based-on-a-condition/m-p/708184#M217578</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-12-25T12:33:34Z</dc:date>
    </item>
  </channel>
</rss>

