<?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 all records until reaching first condition by group? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Delete-all-records-until-reaching-first-condition-by-group/m-p/604653#M175314</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/295821"&gt;@Krueger&lt;/a&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;                                                                                                                             
  input id date: $9. action ;                                                                                                           
  cards ;                                                                                                                               
1  jan012019  1                                                                                                                         
1  feb012019  1                                                                                                                         
1  mar012019  2                                                                                                                         
2  jan012019  2                                                                                                                         
2  feb012019  1                                                                                                                         
;                                                                                                                                       
run ;                                                                                                                                   
                                                                                                                                        
data want ;                                                                                                                             
  do until (last.id) ;                                                                                                                  
    set have ;                                                                                                                          
    by id ;                                                                                                                             
    if action = 2 then _n_ = 0 ;                                                                                                        
    if _n_ = 0 then output ;                                                                                                            
  end ;                                                                                                                                 
run ;            
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 15 Nov 2019 22:51:36 GMT</pubDate>
    <dc:creator>hashman</dc:creator>
    <dc:date>2019-11-15T22:51:36Z</dc:date>
    <item>
      <title>Delete all records until reaching first condition by group?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-all-records-until-reaching-first-condition-by-group/m-p/604647#M175312</link>
      <description>&lt;P&gt;Hi all, I have a far more complex dataset but below is some sample data. Basically I am needing to iterate through the list of ID's and determine the FIRST instance of ACTION&amp;nbsp; = 2. I need all data after this first instance BY ID to be retained and anything before that deleted. Below is what I've tried any pointers on where I'm going wrong?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note* My real data is already sorted and the dates actually appear, I don't believe in this instance they hold any relevance but you'll realize they do not populate correctly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
DATA HAVE;
INPUT ID DATE ACTION;
DATALINES;
1 JAN012019 1
1 FEB012019 1
1 MAR012019 2
2 JAN012019 2
2 FEB012019 1
;RUN;

DATA WANT;
INPUT ID DATE ACTION;
DATALINES;
1 MAR012019 2
2 JAN012019 2
2 FEB012019 1
;
RUN;

DATA WANT;
 SET HAVE;
 DO UNTIL (ID = ID AND ACTION = 2);
 DELETE;
 END;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2019 22:38:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-all-records-until-reaching-first-condition-by-group/m-p/604647#M175312</guid>
      <dc:creator>Krueger</dc:creator>
      <dc:date>2019-11-15T22:38:04Z</dc:date>
    </item>
    <item>
      <title>Re: Delete all records until reaching first condition by group?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-all-records-until-reaching-first-condition-by-group/m-p/604650#M175313</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA HAVE;
INPUT ID DATE :$10. ACTION;
DATALINES;
1 JAN012019 1
1 FEB012019 1
1 MAR012019 2
2 JAN012019 2
2 FEB012019 1
;RUN;

data want;
 do _n_=0 by 0 until(last.id);
  set have;
  by id;
  if ACTION=2 then _n_=1;
  if _n_ then output;
 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;/*Or*/&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 do until(last.id);
  set have;
  by id;
  _iorc_+ ACTION=2;
  if _iorc_ then output;
 end;
 _iorc_=0;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2019 22:51:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-all-records-until-reaching-first-condition-by-group/m-p/604650#M175313</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-11-15T22:51:41Z</dc:date>
    </item>
    <item>
      <title>Re: Delete all records until reaching first condition by group?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-all-records-until-reaching-first-condition-by-group/m-p/604653#M175314</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/295821"&gt;@Krueger&lt;/a&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;                                                                                                                             
  input id date: $9. action ;                                                                                                           
  cards ;                                                                                                                               
1  jan012019  1                                                                                                                         
1  feb012019  1                                                                                                                         
1  mar012019  2                                                                                                                         
2  jan012019  2                                                                                                                         
2  feb012019  1                                                                                                                         
;                                                                                                                                       
run ;                                                                                                                                   
                                                                                                                                        
data want ;                                                                                                                             
  do until (last.id) ;                                                                                                                  
    set have ;                                                                                                                          
    by id ;                                                                                                                             
    if action = 2 then _n_ = 0 ;                                                                                                        
    if _n_ = 0 then output ;                                                                                                            
  end ;                                                                                                                                 
run ;            
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2019 22:51:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-all-records-until-reaching-first-condition-by-group/m-p/604653#M175314</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-11-15T22:51:36Z</dc:date>
    </item>
    <item>
      <title>Re: Delete all records until reaching first condition by group?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-all-records-until-reaching-first-condition-by-group/m-p/604655#M175315</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/295821"&gt;@Krueger&lt;/a&gt;&amp;nbsp; One more fun before I catch the bus to get home, If your dates are numeric SAS dates and it looks like some fun to use them in proc sql &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
DATA HAVE;
INPUT ID DATE :date9. ACTION;
format date date9.;
DATALINES;
1 01JAN2019 1
1 01FEB2019 1
1 01MAR2019 2
2 01JAN2019 2
2 01FEB2019 1
;RUN;

proc sql;
create table want as
select *
from have
group by id
having date&amp;gt;=min(ifn(action=2,date,.))
order by id,date;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Have a good one and a great weekend. Ciao!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2019 23:03:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-all-records-until-reaching-first-condition-by-group/m-p/604655#M175315</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-11-15T23:03:43Z</dc:date>
    </item>
    <item>
      <title>Re: Delete all records until reaching first condition by group?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-all-records-until-reaching-first-condition-by-group/m-p/604656#M175316</link>
      <description>&lt;P&gt;Thank you, I've only tested this on ~10 records of my live data but it seems to be holding up so far.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2019 23:13:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-all-records-until-reaching-first-condition-by-group/m-p/604656#M175316</guid>
      <dc:creator>Krueger</dc:creator>
      <dc:date>2019-11-15T23:13:05Z</dc:date>
    </item>
  </channel>
</rss>

