<?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: Removing observations before and after certain events in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Removing-observations-before-and-after-certain-events/m-p/527625#M143883</link>
    <description>&lt;P&gt;You can loop through a sequence of records until an END event, but only output after encountering the BEGIN:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Row	Time	Group	Event $	Value;
cards;
1	1	1	NA	0
2	2	1	NA	0
3	3	1	Begin	2.2
4	4	1	NA	3.4
5	5	1	NA	2.7
6	6	1	End	3
7	7	1	NA	1
8	1	2	NA	0
9	2	2	Begin	5.5
10	3	2	NA	3.3
11	4	2	End	2.4
12	5	2	NA	0
;

data want (drop=_begin_found);
  do until (event='End     ');
    set have;
    if Event='Begin' then _begin_found='Y';
    if _begin_found='Y' then output;
  end;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 16 Jan 2019 04:25:17 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2019-01-16T04:25:17Z</dc:date>
    <item>
      <title>Removing observations before and after certain events</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-observations-before-and-after-certain-events/m-p/527561#M143837</link>
      <description>&lt;P&gt;&lt;SPAN&gt;My table has some leading and trailing observations that I am trying to remove. I want to remove the rows that come before every 'begin' event and after every 'end' event for every single group. The table resembles the attached. Basically, I want to remove rows 1, 2, 7, 8, and 12.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 23:21:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-observations-before-and-after-certain-events/m-p/527561#M143837</guid>
      <dc:creator>willsilva</dc:creator>
      <dc:date>2019-01-15T23:21:56Z</dc:date>
    </item>
    <item>
      <title>Re: Removing observations before and after certain events</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-observations-before-and-after-certain-events/m-p/527565#M143838</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input Row	Time	Group	Event $	Value;
cards;
1	1	1	NA	0
2	2	1	NA	0
3	3	1	Begin	2.2
4	4	1	NA	3.4
5	5	1	NA	2.7
6	6	1	End	3
7	7	1	NA	1
8	1	2	NA	0
9	2	2	Begin	5.5
10	3	2	NA	3.3
11	4	2	End	2.4
12	5	2	NA	0
;

data want;
set have;
retain k 0;
if event='Begin' then k=1;
else if event='NA' and lag(event)='End' then k=0;
if k;
drop k;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Jan 2019 23:32:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-observations-before-and-after-certain-events/m-p/527565#M143838</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-01-15T23:32:51Z</dc:date>
    </item>
    <item>
      <title>Re: Removing observations before and after certain events</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-observations-before-and-after-certain-events/m-p/527616#M143874</link>
      <description>&lt;P&gt;Another way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT;
  set HAVE;
  if EVENT='Begin' then KEEPIT+1;
  if KEEPIT then output;
  if EVENT='End' then KEEPIT=0;
  drop KEEPIT;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jan 2019 03:23:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-observations-before-and-after-certain-events/m-p/527616#M143874</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-01-16T03:23:33Z</dc:date>
    </item>
    <item>
      <title>Re: Removing observations before and after certain events</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-observations-before-and-after-certain-events/m-p/527625#M143883</link>
      <description>&lt;P&gt;You can loop through a sequence of records until an END event, but only output after encountering the BEGIN:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Row	Time	Group	Event $	Value;
cards;
1	1	1	NA	0
2	2	1	NA	0
3	3	1	Begin	2.2
4	4	1	NA	3.4
5	5	1	NA	2.7
6	6	1	End	3
7	7	1	NA	1
8	1	2	NA	0
9	2	2	Begin	5.5
10	3	2	NA	3.3
11	4	2	End	2.4
12	5	2	NA	0
;

data want (drop=_begin_found);
  do until (event='End     ');
    set have;
    if Event='Begin' then _begin_found='Y';
    if _begin_found='Y' then output;
  end;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Jan 2019 04:25:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-observations-before-and-after-certain-events/m-p/527625#M143883</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-01-16T04:25:17Z</dc:date>
    </item>
  </channel>
</rss>

