<?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: Delete rows based on condition of previous in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Delete-rows-based-on-condition-of-previous/m-p/268428#M53138</link>
    <description>&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Thu, 05 May 2016 02:23:27 GMT</pubDate>
    <dc:creator>Q1983</dc:creator>
    <dc:date>2016-05-05T02:23:27Z</dc:date>
    <item>
      <title>Delete rows based on condition of previous</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-rows-based-on-condition-of-previous/m-p/268363#M53115</link>
      <description>&lt;P&gt;The enclosed spreadsheet contains sample data.&amp;nbsp; For example row 1 is QQQQ and row 3 is BBBB.&amp;nbsp; I want to do the following&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. If BBB occurs after QQQ then delete BBB&lt;/P&gt;
&lt;P&gt;2. if CCC occurs before DDD then delete CCC&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am looking for logic to delete rows based on condtions instead of the usual columns&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sample enclosed&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2016 19:07:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-rows-based-on-condition-of-previous/m-p/268363#M53115</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2016-05-04T19:07:15Z</dc:date>
    </item>
    <item>
      <title>Re: Delete rows based on condition of previous</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-rows-based-on-condition-of-previous/m-p/268383#M53120</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/5629"&gt;@Q1983﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Loan Code $ Date :mmddyy.;
format date mmddyy10.;
cards;
1 QQQQ 5/1/2015 
2 AAAA 2/1/2016 
3 BBBB 1/15/2016 
4 CCCC 1/16/2016 
5 DDDD 1/17/2016
;

data want;
do _n_=1 by 1 until(eof);
  set have end=eof;
  if code='DDDD' then last_d=_n_; /* remember obs. no. of last 'DDDD' */
end;
eof=0;
do _n_=1 by 1 until(eof);
  set have end=eof;
  if code='QQQQ' then del_b=1;    /* set flag "delete 'BBBB'" */
  if ~(code='CCCC' &amp;amp; _n_&amp;lt;last_d | code='BBBB' &amp;amp; del_b) then output;
end;
drop last_d del_b;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Assumptions:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;"If BBB ..." should read "If BBBB ..." etc.&lt;/LI&gt;
&lt;LI&gt;"before" and "after" refer to the order of observations in dataset HAVE.&lt;/LI&gt;
&lt;LI&gt;Dataset HAVE is already sorted appropriately.&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;"before" and "after" do &lt;EM&gt;not&lt;/EM&gt; mean "immediately before" and "immediately after", resp.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;Your real dataset HAVE does not contain BY groups &lt;EM&gt;only within which&lt;/EM&gt; the rules were to be applied.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&lt;SPAN&gt;Please adapt the code appropriately if any of these assumptions do not hold and post further questions if you encounter difficulties.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2016 20:44:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-rows-based-on-condition-of-previous/m-p/268383#M53120</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-05-04T20:44:11Z</dc:date>
    </item>
    <item>
      <title>Re: Delete rows based on condition of previous</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-rows-based-on-condition-of-previous/m-p/268399#M53129</link>
      <description>&lt;P&gt;Another alternative ( input data shamelessly stolen from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh﻿&lt;/a&gt;).&amp;nbsp;This approach does not required data to be sorted, however, it assumes 'before'/'after' is chronological&amp;nbsp;instead of positional.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Loan Code $ Date :mmddyy.;
format date mmddyy10.;
cards;
1 QQQQ 5/1/2015 
2 AAAA 2/1/2016 
3 BBBB 1/15/2016 
4 CCCC 1/16/2016 
5 DDDD 1/17/2016
;

data want;
set have(in=up) have(in=down);
retain last_d first_q;
if up and code='QQQQ' then first_q=min(date,first_q);
if up and code='DDDD' then last_d=max(date,last_d);
if not up;
if not (code='BBBB' and date &amp;gt; first_q);
if not (code='CCCC' and date &amp;lt; last_d);
drop last_d first_q;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 May 2016 22:48:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-rows-based-on-condition-of-previous/m-p/268399#M53129</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2016-05-04T22:48:13Z</dc:date>
    </item>
    <item>
      <title>Re: Delete rows based on condition of previous</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-rows-based-on-condition-of-previous/m-p/268428#M53138</link>
      <description>&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 05 May 2016 02:23:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-rows-based-on-condition-of-previous/m-p/268428#M53138</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2016-05-05T02:23:27Z</dc:date>
    </item>
    <item>
      <title>Re: Delete rows based on condition of previous</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-rows-based-on-condition-of-previous/m-p/268429#M53139</link>
      <description>&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Thu, 05 May 2016 02:24:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-rows-based-on-condition-of-previous/m-p/268429#M53139</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2016-05-05T02:24:03Z</dc:date>
    </item>
  </channel>
</rss>

