<?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: continuous period in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/continuous-period/m-p/510013#M137198</link>
    <description>Can you provide more information - When I look at the input data you have a gap from 3/3/05 to 4/4/05 between obs 2 &amp;amp; 3, which is more than 7 days. Yet the output suggests you want to go from 01/01/05 to 05/05/05. Thanks</description>
    <pubDate>Fri, 02 Nov 2018 18:56:02 GMT</pubDate>
    <dc:creator>AMSAS</dc:creator>
    <dc:date>2018-11-02T18:56:02Z</dc:date>
    <item>
      <title>continuous period</title>
      <link>https://communities.sas.com/t5/SAS-Programming/continuous-period/m-p/509918#M137158</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
informat start end mmddyy10.;
format start end date9.;
input id drug start end;
cards;
1  a  1/1/2005  2/17/2005
1  a  2/7/2005  3/3/2005
1  a  3/7/2005  5/5/2005
1  a  5/30/2005 8/9/2005
;run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want to create a continuous&amp;nbsp;period allowing only 7 days gap between the end date of the period and the start of the next one&amp;nbsp;&lt;/P&gt;&lt;P&gt;output&lt;/P&gt;&lt;P&gt;id start end&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;1/1/2005&amp;nbsp; 5/15/2005&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 21:24:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/continuous-period/m-p/509918#M137158</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2018-11-02T21:24:02Z</dc:date>
    </item>
    <item>
      <title>Re: continuous period</title>
      <link>https://communities.sas.com/t5/SAS-Programming/continuous-period/m-p/510013#M137198</link>
      <description>Can you provide more information - When I look at the input data you have a gap from 3/3/05 to 4/4/05 between obs 2 &amp;amp; 3, which is more than 7 days. Yet the output suggests you want to go from 01/01/05 to 05/05/05. Thanks</description>
      <pubDate>Fri, 02 Nov 2018 18:56:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/continuous-period/m-p/510013#M137198</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2018-11-02T18:56:02Z</dc:date>
    </item>
    <item>
      <title>Re: continuous period</title>
      <link>https://communities.sas.com/t5/SAS-Programming/continuous-period/m-p/510080#M137234</link>
      <description>&lt;P&gt;Thank you for the response. I adjusted the dates. I want to allow a gap of 7 days but if there is overlap in the dates such as in the first and the second row (there is an overlap of 10 days) I want to add the 10 days to the end date as refected in the output.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 21:26:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/continuous-period/m-p/510080#M137234</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2018-11-02T21:26:16Z</dc:date>
    </item>
    <item>
      <title>Re: continuous period</title>
      <link>https://communities.sas.com/t5/SAS-Programming/continuous-period/m-p/510114#M137253</link>
      <description>&lt;P&gt;You didn't show multiple ID's, but I presume the dataset is sorted by ID/START, so this program checks for a change in ID:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
informat start end mmddyy10.;
format start end date9.;
input id drug :$1. start end;
cards;
1  a  1/1/2005  2/17/2005
1  a  2/7/2005  3/3/2005
1  a  3/7/2005  5/5/2005
1  a  5/30/2005 8/9/2005
;run;

data want (drop=_:);
  set have (keep=id);
  by id;

  merge have 
        have (firstobs=2 keep=start rename=(start=_nxtstart));

  retain _start;
  if first.id or start &amp;gt; lag(end)+7 then _start=start;
  if last.id or _nxtstart&amp;gt;end+7;

  start=_start;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;I want to test for first.id and last.id, but I couldn't do &lt;BR /&gt;&amp;nbsp;&amp;nbsp; MERGE HAVE&amp;nbsp;&amp;nbsp; HAVE (firstobs=2 keep=start rename=(start=_nxtstart));&lt;BR /&gt;&amp;nbsp;&amp;nbsp; BY ID;&lt;BR /&gt;because the 2nd ID group and all subsequent ID groups, would not have _NXTSTART one observation after the current obs.&amp;nbsp; So the solution is to
&lt;OL&gt;
&lt;LI&gt;Use&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SET HAVE (keep=id); BY ID;&lt;BR /&gt;which sets up the dummy first.id and last.id as needed,&lt;BR /&gt;&amp;nbsp; and&lt;/LI&gt;
&lt;LI&gt;MERGE HAVE&amp;nbsp; HAVE (firstobs=2 keep=start rename=(start=_nxtstart);&amp;nbsp;&amp;nbsp; WITHOUT a following BY ID statement.&amp;nbsp; This keeps _nxtstart one obs ahead of start, even when changing ID groups.&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Sat, 03 Nov 2018 04:31:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/continuous-period/m-p/510114#M137253</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-11-03T04:31:17Z</dc:date>
    </item>
  </channel>
</rss>

