<?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: Generic Code to Create Date Intervals With Multiple Rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Generic-Code-to-Create-Date-Intervals-With-Multiple-Rows/m-p/476014#M122462</link>
    <description>Would you mind putting it in the terms of the variables:&lt;BR /&gt;unique_ID1 service_from_date1 service_to_date1</description>
    <pubDate>Fri, 06 Jul 2018 14:09:36 GMT</pubDate>
    <dc:creator>brubin</dc:creator>
    <dc:date>2018-07-06T14:09:36Z</dc:date>
    <item>
      <title>Generic Code to Create Date Intervals With Multiple Rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generic-Code-to-Create-Date-Intervals-With-Multiple-Rows/m-p/476000#M122458</link>
      <description>&lt;P&gt;Hi everyone.&lt;/P&gt;&lt;P&gt;I was wondering if it is possible to write a code that combines date intervals with multiple rows. For example I would like this:&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;ID&lt;/STRONG&gt;&lt;/U&gt; &lt;U&gt;&lt;STRONG&gt;start_date&lt;/STRONG&gt;&lt;/U&gt; &lt;U&gt;&lt;STRONG&gt;end_date&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp;1/1/17&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;1/10/17&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp;1/11/17&amp;nbsp; &amp;nbsp; &amp;nbsp; 1/14/17&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp;1/20/17&amp;nbsp; &amp;nbsp; &amp;nbsp; 1/22/17&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp;1/4/17&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/8/17&lt;/P&gt;&lt;P&gt;To output:&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;ID&lt;/STRONG&gt;&lt;/U&gt;&lt;STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;U&gt;&lt;STRONG&gt;start_date&lt;/STRONG&gt;&lt;/U&gt;&lt;STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;U&gt;&lt;STRONG&gt;end_date&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp;1/1/17&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;1/14/17&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp;1/20/17&amp;nbsp; &amp;nbsp; &amp;nbsp; 1/22/17&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp;1/4/17&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1/8/17&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jul 2018 13:49:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generic-Code-to-Create-Date-Intervals-With-Multiple-Rows/m-p/476000#M122458</guid>
      <dc:creator>brubin</dc:creator>
      <dc:date>2018-07-06T13:49:30Z</dc:date>
    </item>
    <item>
      <title>Re: Generic Code to Create Date Intervals With Multiple Rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generic-Code-to-Create-Date-Intervals-With-Multiple-Rows/m-p/476008#M122459</link>
      <description>&lt;P&gt;The answer is yes.&amp;nbsp; Just control the output statement and output and retain the dates, e.g. (not tested as no test data in the form of a datastep):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  retain start end;
  by id;
  if first.id then start=start_date;
  else if start_date ne lag(end_date)+1 then do;
    end_date=lag(end_date);
    output;
    start=start_date
  end;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Jul 2018 13:57:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generic-Code-to-Create-Date-Intervals-With-Multiple-Rows/m-p/476008#M122459</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-07-06T13:57:36Z</dc:date>
    </item>
    <item>
      <title>Re: Generic Code to Create Date Intervals With Multiple Rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generic-Code-to-Create-Date-Intervals-With-Multiple-Rows/m-p/476014#M122462</link>
      <description>Would you mind putting it in the terms of the variables:&lt;BR /&gt;unique_ID1 service_from_date1 service_to_date1</description>
      <pubDate>Fri, 06 Jul 2018 14:09:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generic-Code-to-Create-Date-Intervals-With-Multiple-Rows/m-p/476014#M122462</guid>
      <dc:creator>brubin</dc:creator>
      <dc:date>2018-07-06T14:09:36Z</dc:date>
    </item>
    <item>
      <title>Re: Generic Code to Create Date Intervals With Multiple Rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generic-Code-to-Create-Date-Intervals-With-Multiple-Rows/m-p/476021#M122466</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $ start_date : mmddyy10. end_date : mmddyy10.;
format start_date end_date mmddyy10.;
cards;
A     1/1/17        1/10/17
A     1/11/17      1/14/17
A     1/20/17      1/22/17
B     1/4/17        1/8/17
;
run;
data temp;
 set have;
 by id;
 if first.id or start_date ne lag(end_date)+1 then group+1;
run;
data want;
 set temp(rename=(start_date=_start_date));
 by group;
 retain start_date;
 if first.group then start_date=_start_date;
 if last.group;
 format start_date mmddyy10.;
 drop _start_date;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Jul 2018 14:36:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generic-Code-to-Create-Date-Intervals-With-Multiple-Rows/m-p/476021#M122466</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-07-06T14:36:58Z</dc:date>
    </item>
  </channel>
</rss>

