<?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: Flag consecutive and non consecutive dates in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Flag-consecutive-and-non-consecutive-dates/m-p/842683#M36535</link>
    <description>&lt;P&gt;If the data are sorted by ID/start, then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=next_:);
  set have (keep=id);
  by id;
  merge have
        have (firstobs=2 keep=start rename=(start=next_start);

  if first.id=1 or start-1 ^=lag(end) then backward_consecutive='N';
  else backwards_consecutive='Y';

  if last.id=1 or end+1 ^= next_start then forward_consecutive='N';
  else forward_consecutive='Y';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This uses a self-merge with offset approach&amp;nbsp; (i.e. the firstobs=2 in one of the MERGE argument.&amp;nbsp; It also uses SET plus BY statements to generate the first.id and last.id dummies.&lt;/P&gt;</description>
    <pubDate>Sat, 05 Nov 2022 16:51:39 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2022-11-05T16:51:39Z</dc:date>
    <item>
      <title>Flag consecutive and non consecutive dates</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Flag-consecutive-and-non-consecutive-dates/m-p/842681#M36534</link>
      <description>&lt;P&gt;Guys, &lt;BR /&gt;I need to do the following but I don't know how. &lt;BR /&gt;I need to distinguish the first case from the second:&lt;/P&gt;
&lt;P&gt;case1:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;ID &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Start &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;0001 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; - &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 18DEC2019&lt;BR /&gt;&amp;nbsp; &amp;nbsp;0001 &amp;nbsp; &amp;nbsp;19DEC2019 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&lt;/P&gt;
&lt;P&gt;case2:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;ID &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Start &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; End &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;0001 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; - &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 18DEC2019&lt;BR /&gt;&amp;nbsp; &amp;nbsp;0001 &amp;nbsp; &amp;nbsp;11JAN2020 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Meaning, is there a way to flag if the end is continuous with the start from the case in which there is a gap from the previous end and the next start? Continuity in terms of years is sufficient.&lt;/P&gt;
&lt;P&gt;Thank you in advance&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Nov 2022 16:45:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Flag-consecutive-and-non-consecutive-dates/m-p/842681#M36534</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2022-11-05T16:45:35Z</dc:date>
    </item>
    <item>
      <title>Re: Flag consecutive and non consecutive dates</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Flag-consecutive-and-non-consecutive-dates/m-p/842683#M36535</link>
      <description>&lt;P&gt;If the data are sorted by ID/start, then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=next_:);
  set have (keep=id);
  by id;
  merge have
        have (firstobs=2 keep=start rename=(start=next_start);

  if first.id=1 or start-1 ^=lag(end) then backward_consecutive='N';
  else backwards_consecutive='Y';

  if last.id=1 or end+1 ^= next_start then forward_consecutive='N';
  else forward_consecutive='Y';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This uses a self-merge with offset approach&amp;nbsp; (i.e. the firstobs=2 in one of the MERGE argument.&amp;nbsp; It also uses SET plus BY statements to generate the first.id and last.id dummies.&lt;/P&gt;</description>
      <pubDate>Sat, 05 Nov 2022 16:51:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Flag-consecutive-and-non-consecutive-dates/m-p/842683#M36535</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-11-05T16:51:39Z</dc:date>
    </item>
    <item>
      <title>Re: Flag consecutive and non consecutive dates</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Flag-consecutive-and-non-consecutive-dates/m-p/842691#M36536</link>
      <description>Thank you very much! It works perfectly!</description>
      <pubDate>Sat, 05 Nov 2022 18:03:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Flag-consecutive-and-non-consecutive-dates/m-p/842691#M36536</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2022-11-05T18:03:42Z</dc:date>
    </item>
  </channel>
</rss>

