<?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 record based on a particular value in a group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Delete-record-based-on-a-particular-value-in-a-group/m-p/578234#M163950</link>
    <description>&lt;P&gt;this is clever! I ran this and found that my data has duplications for DF. But I would want to keep the DF step with the latest sequence number. The other thing is that i got some duplicate outputs in my result for some reason. I will go with the data step solution but thank you for this. i have never thought about joining a table back on itself...&lt;/P&gt;</description>
    <pubDate>Wed, 31 Jul 2019 22:06:40 GMT</pubDate>
    <dc:creator>TheNovice</dc:creator>
    <dc:date>2019-07-31T22:06:40Z</dc:date>
    <item>
      <title>Delete record based on a particular value in a group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-record-based-on-a-particular-value-in-a-group/m-p/578141#M163926</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have an extract like this with multiple bans and records. It is sorted by ban and ent_seq_no. What i want to do is only keep records for a ban after the DF step only (including DF). So in this case the first 3 records would be deleted...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am thinking that deleting the records where ent_seq_no is less than the seq no for the record that has code DF is the way but i am not sure how to write it...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;BAN&lt;/TD&gt;&lt;TD&gt;ENT_SEQ_NO&lt;/TD&gt;&lt;TD&gt;COL_ACTV_CODE&lt;/TD&gt;&lt;TD&gt;COL_ACTV_DATE&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10987&lt;/TD&gt;&lt;TD&gt;941020677&lt;/TD&gt;&lt;TD&gt;D2&lt;/TD&gt;&lt;TD&gt;04JUL2019:00:00:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10987&lt;/TD&gt;&lt;TD&gt;941953583&lt;/TD&gt;&lt;TD&gt;D3&lt;/TD&gt;&lt;TD&gt;10JUL2019:00:00:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10987&lt;/TD&gt;&lt;TD&gt;942384352&lt;/TD&gt;&lt;TD&gt;3S&lt;/TD&gt;&lt;TD&gt;12JUL2019:00:00:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10987&lt;/TD&gt;&lt;TD&gt;942902222&lt;/TD&gt;&lt;TD&gt;DF&lt;/TD&gt;&lt;TD&gt;16JUL2019:00:00:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10987&lt;/TD&gt;&lt;TD&gt;943965758&lt;/TD&gt;&lt;TD&gt;E&lt;/TD&gt;&lt;TD&gt;23JUL2019:00:00:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10987&lt;/TD&gt;&lt;TD&gt;944352184&lt;/TD&gt;&lt;TD&gt;1S&lt;/TD&gt;&lt;TD&gt;25JUL2019:00:00:00&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Wed, 31 Jul 2019 16:57:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-record-based-on-a-particular-value-in-a-group/m-p/578141#M163926</guid>
      <dc:creator>TheNovice</dc:creator>
      <dc:date>2019-07-31T16:57:01Z</dc:date>
    </item>
    <item>
      <title>Re: Delete record based on a particular value in a group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-record-based-on-a-particular-value-in-a-group/m-p/578150#M163929</link>
      <description>&lt;P&gt;Retain a flag variable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by ban;
retain keepflag;
if first.ban then keepflag = 0;
if col_actv_code = 'DF' then keepflag = 1;
if keepflag;
drop keepflag;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Jul 2019 17:16:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-record-based-on-a-particular-value-in-a-group/m-p/578150#M163929</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-07-31T17:16:06Z</dc:date>
    </item>
    <item>
      <title>Re: Delete record based on a particular value in a group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-record-based-on-a-particular-value-in-a-group/m-p/578151#M163930</link>
      <description>&lt;P&gt;This may get you started.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   by ban ent_seq_no;
   retain flag;
   if first.ban then flag=0;
   if flag=0 and col_actv_code='DF' then flag=1;
   /* this keeps records after the flag is set*/
   if flag=1;
run;&lt;/PRE&gt;
&lt;P&gt;You may want to drop the Flag variable after verifying that this works.&lt;/P&gt;
&lt;P&gt;The BY sets special variable First. and Last. that you can check to do something for the group, in this case reset a flag. The flag should only be reset to 1 when 1) it is currently zero and 2) the value of DF is encountered. The Flag will stay at 1 until the next BAN group is encountered.&lt;/P&gt;
&lt;P&gt;The last IF indicates which values get written to the output set.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2019 17:17:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-record-based-on-a-particular-value-in-a-group/m-p/578151#M163930</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-07-31T17:17:54Z</dc:date>
    </item>
    <item>
      <title>Re: Delete record based on a particular value in a group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-record-based-on-a-particular-value-in-a-group/m-p/578152#M163931</link>
      <description>&lt;P&gt;It worked! I was trying this to no avail&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;DATA TEST1;&lt;BR /&gt;SET TEST;&lt;BR /&gt;count +1;&lt;BR /&gt;do until (first.ban);&lt;BR /&gt;BY BAN;&lt;BR /&gt;IF COL_ACTV_CODE = 'DF' THEN COUNT= 0;&lt;BR /&gt;end;&lt;BR /&gt;RUN;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2019 17:17:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-record-based-on-a-particular-value-in-a-group/m-p/578152#M163931</guid>
      <dc:creator>TheNovice</dc:creator>
      <dc:date>2019-07-31T17:17:59Z</dc:date>
    </item>
    <item>
      <title>Re: Delete record based on a particular value in a group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-record-based-on-a-particular-value-in-a-group/m-p/578153#M163932</link>
      <description>&lt;P&gt;thank you so much. your response is the same as above. The explanation helps. I think i have a much better understanding of how to work problems like this now.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2019 17:20:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-record-based-on-a-particular-value-in-a-group/m-p/578153#M163932</guid>
      <dc:creator>TheNovice</dc:creator>
      <dc:date>2019-07-31T17:20:53Z</dc:date>
    </item>
    <item>
      <title>Re: Delete record based on a particular value in a group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-record-based-on-a-particular-value-in-a-group/m-p/578157#M163933</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input BAN	ENT_SEQ_NO	COL_ACTV_CODE $	COL_ACTV_DATE :datetime20.;
format COL_ACTV_DATE datetime20.;
cards;
10987	941020677	D2	04JUL2019:00:00:00
10987	941953583	D3	10JUL2019:00:00:00
10987	942384352	3S	12JUL2019:00:00:00
10987	942902222	DF	16JUL2019:00:00:00
10987	943965758	E	23JUL2019:00:00:00
10987	944352184	1S	25JUL2019:00:00:00
;

proc sql;
create table want as
select a.*
from have a ,(select ban,min(COL_ACTV_DATE) as d from have where COL_ACTV_CODE='DF' group by ban) b
where a.ban=b.ban and a.COL_ACTV_DATE&amp;gt;=d;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Jul 2019 18:08:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-record-based-on-a-particular-value-in-a-group/m-p/578157#M163933</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-07-31T18:08:32Z</dc:date>
    </item>
    <item>
      <title>Re: Delete record based on a particular value in a group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-record-based-on-a-particular-value-in-a-group/m-p/578234#M163950</link>
      <description>&lt;P&gt;this is clever! I ran this and found that my data has duplications for DF. But I would want to keep the DF step with the latest sequence number. The other thing is that i got some duplicate outputs in my result for some reason. I will go with the data step solution but thank you for this. i have never thought about joining a table back on itself...&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2019 22:06:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-record-based-on-a-particular-value-in-a-group/m-p/578234#M163950</guid>
      <dc:creator>TheNovice</dc:creator>
      <dc:date>2019-07-31T22:06:40Z</dc:date>
    </item>
  </channel>
</rss>

