<?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 Uninterrupted records with a given value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Uninterrupted-records-with-a-given-value/m-p/417823#M102630</link>
    <description>&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Hello,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;I am seeking help. I need to extract records with same TYPE ('NO', in this case) showing up uninterrupted based on each date. It is ok 'NO' showed up with other values, but they have to be uninterrupted with no other value on a differnent date in between (i.e. #6) and 'NO' also had to be the last time it showed up (#2 &amp;amp; 5).&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Thank you ver much in advance!!!&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;id&amp;nbsp;&amp;nbsp;&amp;nbsp;ISSUE_DATE&amp;nbsp;&amp;nbsp; TYPE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 16OCT2015&amp;nbsp;&amp;nbsp;&amp;nbsp; BC &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 16OCT2015&amp;nbsp;&amp;nbsp;&amp;nbsp; NO &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 15FEB2017&amp;nbsp;&amp;nbsp;&amp;nbsp; CD&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 15FEB2017&amp;nbsp;&amp;nbsp;&amp;nbsp; NO&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp; 16JAN2016&amp;nbsp;&amp;nbsp;&amp;nbsp; NO&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp; 20FEB2017&amp;nbsp;&amp;nbsp;&amp;nbsp; NO&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;6&amp;nbsp;&amp;nbsp;&amp;nbsp; 10DEC2015&amp;nbsp;&amp;nbsp;&amp;nbsp; NO&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;6&amp;nbsp;&amp;nbsp;&amp;nbsp; 16MAR2016&amp;nbsp;&amp;nbsp;&amp;nbsp; CD&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;6&amp;nbsp;&amp;nbsp;&amp;nbsp; 21NOV2017&amp;nbsp;&amp;nbsp;&amp;nbsp; NO&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;7&amp;nbsp;&amp;nbsp;&amp;nbsp; 15DEC2015&amp;nbsp;&amp;nbsp;&amp;nbsp; NO&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;7&amp;nbsp;&amp;nbsp;&amp;nbsp; 15MAR2016&amp;nbsp;&amp;nbsp;&amp;nbsp; NO&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;7&amp;nbsp;&amp;nbsp;&amp;nbsp; 25NOV2017&amp;nbsp;&amp;nbsp;&amp;nbsp; BC&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Desired output with IDS 6 &amp;amp; 7 removed.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;id&amp;nbsp;&amp;nbsp;&amp;nbsp;ISSUE_DATE&amp;nbsp;&amp;nbsp; TYPE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 16OCT2015&amp;nbsp;&amp;nbsp;&amp;nbsp; BC &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 16OCT2015&amp;nbsp;&amp;nbsp;&amp;nbsp; NO &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 15FEB2017&amp;nbsp;&amp;nbsp;&amp;nbsp; CD&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 15FEB2017&amp;nbsp;&amp;nbsp;&amp;nbsp; NO&amp;nbsp; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 18AUG2017&amp;nbsp;&amp;nbsp;&amp;nbsp; IR&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp; 16JAN2016&amp;nbsp;&amp;nbsp;&amp;nbsp; NO&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp; 20FEB2017&amp;nbsp;&amp;nbsp;&amp;nbsp; NO&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 01 Dec 2017 19:36:25 GMT</pubDate>
    <dc:creator>MR1993</dc:creator>
    <dc:date>2017-12-01T19:36:25Z</dc:date>
    <item>
      <title>Uninterrupted records with a given value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Uninterrupted-records-with-a-given-value/m-p/417823#M102630</link>
      <description>&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Hello,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;I am seeking help. I need to extract records with same TYPE ('NO', in this case) showing up uninterrupted based on each date. It is ok 'NO' showed up with other values, but they have to be uninterrupted with no other value on a differnent date in between (i.e. #6) and 'NO' also had to be the last time it showed up (#2 &amp;amp; 5).&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Thank you ver much in advance!!!&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;id&amp;nbsp;&amp;nbsp;&amp;nbsp;ISSUE_DATE&amp;nbsp;&amp;nbsp; TYPE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 16OCT2015&amp;nbsp;&amp;nbsp;&amp;nbsp; BC &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 16OCT2015&amp;nbsp;&amp;nbsp;&amp;nbsp; NO &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 15FEB2017&amp;nbsp;&amp;nbsp;&amp;nbsp; CD&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 15FEB2017&amp;nbsp;&amp;nbsp;&amp;nbsp; NO&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp; 16JAN2016&amp;nbsp;&amp;nbsp;&amp;nbsp; NO&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp; 20FEB2017&amp;nbsp;&amp;nbsp;&amp;nbsp; NO&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;6&amp;nbsp;&amp;nbsp;&amp;nbsp; 10DEC2015&amp;nbsp;&amp;nbsp;&amp;nbsp; NO&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;6&amp;nbsp;&amp;nbsp;&amp;nbsp; 16MAR2016&amp;nbsp;&amp;nbsp;&amp;nbsp; CD&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;6&amp;nbsp;&amp;nbsp;&amp;nbsp; 21NOV2017&amp;nbsp;&amp;nbsp;&amp;nbsp; NO&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;7&amp;nbsp;&amp;nbsp;&amp;nbsp; 15DEC2015&amp;nbsp;&amp;nbsp;&amp;nbsp; NO&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;7&amp;nbsp;&amp;nbsp;&amp;nbsp; 15MAR2016&amp;nbsp;&amp;nbsp;&amp;nbsp; NO&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;7&amp;nbsp;&amp;nbsp;&amp;nbsp; 25NOV2017&amp;nbsp;&amp;nbsp;&amp;nbsp; BC&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Desired output with IDS 6 &amp;amp; 7 removed.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;id&amp;nbsp;&amp;nbsp;&amp;nbsp;ISSUE_DATE&amp;nbsp;&amp;nbsp; TYPE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 16OCT2015&amp;nbsp;&amp;nbsp;&amp;nbsp; BC &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 16OCT2015&amp;nbsp;&amp;nbsp;&amp;nbsp; NO &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 15FEB2017&amp;nbsp;&amp;nbsp;&amp;nbsp; CD&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 15FEB2017&amp;nbsp;&amp;nbsp;&amp;nbsp; NO&amp;nbsp; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 18AUG2017&amp;nbsp;&amp;nbsp;&amp;nbsp; IR&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp; 16JAN2016&amp;nbsp;&amp;nbsp;&amp;nbsp; NO&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp; 20FEB2017&amp;nbsp;&amp;nbsp;&amp;nbsp; NO&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Dec 2017 19:36:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Uninterrupted-records-with-a-given-value/m-p/417823#M102630</guid>
      <dc:creator>MR1993</dc:creator>
      <dc:date>2017-12-01T19:36:25Z</dc:date>
    </item>
    <item>
      <title>Re: Uninterrupted records with a given value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Uninterrupted-records-with-a-given-value/m-p/417836#M102634</link>
      <description>&lt;P&gt;Where does this row in your output come from?&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 18AUG2017&amp;nbsp;&amp;nbsp;&amp;nbsp; IR&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;It wasn't in the input.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Dec 2017 20:03:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Uninterrupted-records-with-a-given-value/m-p/417836#M102634</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-12-01T20:03:16Z</dc:date>
    </item>
    <item>
      <title>Re: Uninterrupted records with a given value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Uninterrupted-records-with-a-given-value/m-p/417857#M102638</link>
      <description>Right. This line should not be in the output.&lt;BR /&gt;2 18AUG2017 IR</description>
      <pubDate>Fri, 01 Dec 2017 21:04:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Uninterrupted-records-with-a-given-value/m-p/417857#M102638</guid>
      <dc:creator>MR1993</dc:creator>
      <dc:date>2017-12-01T21:04:16Z</dc:date>
    </item>
    <item>
      <title>Re: Uninterrupted records with a given value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Uninterrupted-records-with-a-given-value/m-p/417921#M102655</link>
      <description>&lt;P&gt;This will do it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id   ISSUE_DATE :date9.   TYPE $;
format issue_date date9.;
datalines;
2    16OCT2015    BC 
2    16OCT2015    NO 
2    15FEB2017    CD     
2    15FEB2017    NO 
5    16JAN2016    NO
5    20FEB2017    NO
6    10DEC2015    NO
6    16MAR2016    CD
6    21NOV2017    NO
7    15DEC2015    NO
7    15MAR2016    NO
7    25NOV2017    BC
;

proc sql;
create table want as
select * from have
where id in 
    (select a.id 
     from 
        (select id, count(distinct issue_date) as n 
         from have 
         group by id, type) as a
        inner join 
        (select id, count(distinct issue_date) as n 
         from have 
         group by id) as b
        on a.id=b.id and a.n=b.n);
select * from want;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 02 Dec 2017 04:21:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Uninterrupted-records-with-a-given-value/m-p/417921#M102655</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-12-02T04:21:44Z</dc:date>
    </item>
    <item>
      <title>Re: Uninterrupted records with a given value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Uninterrupted-records-with-a-given-value/m-p/417933#M102661</link>
      <description>&lt;P&gt;What you gonna do if data like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;7&amp;nbsp;&amp;nbsp;&amp;nbsp; 15DEC2015&amp;nbsp; &amp;nbsp; BC&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;7&amp;nbsp;&amp;nbsp;&amp;nbsp; 15MAR2016&amp;nbsp;&amp;nbsp;&amp;nbsp; NO&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;7&amp;nbsp;&amp;nbsp;&amp;nbsp; 25NOV2017&amp;nbsp; &amp;nbsp; NO&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id   ISSUE_DATE :date9.   TYPE $;
format issue_date date9.;
datalines;
2    16OCT2015    BC 
2    16OCT2015    NO 
2    15FEB2017    CD     
2    15FEB2017    NO 
5    16JAN2016    NO
5    20FEB2017    NO
6    10DEC2015    NO
6    16MAR2016    CD
6    21NOV2017    NO
7    15DEC2015    NO
7    15MAR2016    NO
7    25NOV2017    BC
;

data want;
 if _n_=1 then do;
 if 0 then set have;
  declare hash h();
  h.definekey('ISSUE_DATE');
  h.definedone();
  declare hash hh();
  hh.definekey('ISSUE_DATE','TYPE');
  hh.definedone();
 end;

do until(last.id);
 set have;
 by id;
 h.ref();
 if type='NO' then hh.ref();
end;
if type='NO' and h.num_items=hh.num_items then yes=1;
do until(last.id);
 set have;
 by id;
 if yes then output;
end;
h.clear();
hh.clear();
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Dec 2017 11:29:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Uninterrupted-records-with-a-given-value/m-p/417933#M102661</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-12-02T11:29:23Z</dc:date>
    </item>
    <item>
      <title>Re: Uninterrupted records with a given value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Uninterrupted-records-with-a-given-value/m-p/418289#M102747</link>
      <description>&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When this happens, output the last two rows.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What you gonna do if data like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;7&amp;nbsp;&amp;nbsp;&amp;nbsp; 15DEC2015&amp;nbsp; &amp;nbsp; BC&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;7&amp;nbsp;&amp;nbsp;&amp;nbsp; 15MAR2016&amp;nbsp;&amp;nbsp;&amp;nbsp; NO&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;7&amp;nbsp;&amp;nbsp;&amp;nbsp; 25NOV2017&amp;nbsp; &amp;nbsp; NO&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 20:27:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Uninterrupted-records-with-a-given-value/m-p/418289#M102747</guid>
      <dc:creator>MR1993</dc:creator>
      <dc:date>2017-12-04T20:27:00Z</dc:date>
    </item>
    <item>
      <title>Re: Uninterrupted records with a given value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Uninterrupted-records-with-a-given-value/m-p/418353#M102762</link>
      <description>&lt;P&gt;You want to keep all records for any ID in which there are two dates having a type = "NO" record with no intervening dates.&amp;nbsp; This program has two data steps, but processes the data set file only once.&amp;nbsp; Because the first data step creates a data set view, its output will only be generated when a subsequent step refers to that view:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data need (keep=id) /view=need;
  set have (in=in1 where=(type='NO')) have (where=(type^='NO'));
  by id issue_date;
  if first.issue_date;
  consecutive_nos=(in1=1 and lag(in1)=1);
  if consecutive_nos=1 and first.id=0;
run;
  
data want;
  merge have need (in=inkeep);
  by id;
  if inkeep;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Notes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The data set view NEED reads in data set have with the NO's interleaved with other records in such a way that the first record for a given id/issue_date is a type "NO", assuming one is present for that date.&lt;/LI&gt;
&lt;LI&gt;The subsetting IF filter through only records starting each date (which means all the 'NO' and only some of the others).&amp;nbsp; This also means the LAG test is done only once per date.&lt;/LI&gt;
&lt;LI&gt;Then just test for consecutive no's by using the lag function, and filter out cases in which consecutive no's cross from one ID to the next.&lt;/LI&gt;
&lt;LI&gt;The 2nd step is a normal merge.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Tue, 05 Dec 2017 02:19:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Uninterrupted-records-with-a-given-value/m-p/418353#M102762</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-12-05T02:19:30Z</dc:date>
    </item>
    <item>
      <title>Re: Uninterrupted records with a given value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Uninterrupted-records-with-a-given-value/m-p/418461#M102793</link>
      <description>&lt;P&gt;OK. Here is .after that, you can delete the first row which don't have 'NO'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id   ISSUE_DATE :date9.   TYPE $;
format issue_date date9.;
datalines;
2    16OCT2015    BC 
2    16OCT2015    NO 
2    15FEB2017    CD     
2    15FEB2017    NO 
5    16JAN2016    NO
5    20FEB2017    NO
6    10DEC2015    NO
6    16MAR2016    CD
6    21NOV2017    NO
7    15DEC2015    NO
7    15MAR2016    NO
7    25NOV2017    BC
8    15DEC2015    BC
8    15MAR2016    NO
8    25NOV2017    NO
;

data want;
 if _n_=1 then do;
 if 0 then set have;
  declare hash h();
  h.definekey('ISSUE_DATE');
  h.definedone();
  declare hash hh();
  hh.definekey('ISSUE_DATE','TYPE');
  hh.definedone();
 end;
n=0;
do until(last.id);
 set have;
 by id ISSUE_DATE;
 n+first.ISSUE_DATE;
 if n ne 1 then do;
   h.ref();
   if type='NO' then hh.ref();
 end;
end; 
if h.num_items=hh.num_items then yes=1;
do until(last.id);
 set have;
 by id;
 if yes then output;
end;
h.clear();
hh.clear();
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Dec 2017 12:50:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Uninterrupted-records-with-a-given-value/m-p/418461#M102793</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-12-05T12:50:14Z</dc:date>
    </item>
    <item>
      <title>Re: Uninterrupted records with a given value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Uninterrupted-records-with-a-given-value/m-p/423946#M104315</link>
      <description>&lt;P&gt;Thanks very much to those who replied!!!&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Dec 2017 19:12:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Uninterrupted-records-with-a-given-value/m-p/423946#M104315</guid>
      <dc:creator>Max503</dc:creator>
      <dc:date>2017-12-28T19:12:08Z</dc:date>
    </item>
  </channel>
</rss>

