<?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 a group based on a particular observation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Delete-a-group-based-on-a-particular-observation/m-p/571942#M161369</link>
    <description>&lt;P&gt;Using the variable names from your sample data, this would be one way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;do until (last.id);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; by id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if actv_code='S' then output_flag='N';&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;else output_flag='Y';&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;do until (last.id);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; by id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if output_flag='Y' then output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;drop output_flag;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
    <pubDate>Tue, 09 Jul 2019 02:29:08 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2019-07-09T02:29:08Z</dc:date>
    <item>
      <title>Delete a group based on a particular observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-a-group-based-on-a-particular-observation/m-p/571931#M161360</link>
      <description>&lt;P&gt;There is data that I have sorted using the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=RESTORED ; by ID ent_seq_no descending col_actv_code ; quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get the following. below is an example of a type of group in the data. What I want to do is delete these records( all of them) if the last actv_code = 'S'. I only want to delete the group of ID's if the last code is S. I cannot figure out how.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp;&amp;nbsp; ENT_SEQ_NO&amp;nbsp; ACTV_CODE&lt;BR /&gt;0935 &amp;nbsp; &amp;nbsp; 913240851 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; S&lt;BR /&gt;0935 &amp;nbsp; &amp;nbsp; 913863008 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; K&lt;BR /&gt;0935 &amp;nbsp; &amp;nbsp; 915287558 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; S&lt;BR /&gt;0935 &amp;nbsp; &amp;nbsp; 915733042 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; K&lt;BR /&gt;0935 &amp;nbsp; &amp;nbsp; 919660717 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; S&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data r ;&lt;BR /&gt;set restored;&lt;BR /&gt;by ban ent_seq_no descending col_actv_code;&lt;BR /&gt;if not last.ban then delete;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any direction is appreciated.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2019 01:05:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-a-group-based-on-a-particular-observation/m-p/571931#M161360</guid>
      <dc:creator>TheNovice</dc:creator>
      <dc:date>2019-07-09T01:05:12Z</dc:date>
    </item>
    <item>
      <title>Re: Delete a group based on a particular observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-a-group-based-on-a-particular-observation/m-p/571940#M161368</link>
      <description>&lt;P&gt;This could work:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	set restored end=lastRow;
	length toBeDeleted $ 500;
	by ID;
	if last.id and upcase(col_actv_code) = "S" then do;
			toBeDeleted = cat(strip(toBeDeleted)," '",strip(ID),"' ");
	end;
	if lastRow then call symputx ("toBeDeleted",toBeDeleted);
run;

proc sql noprint;
	create table Restored_2 as 
	select * from Restored 
	where ID not in (&amp;amp;toBeDeleted);
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Potentially you could sort your data the other way around, so that the first row is the S and if so, then you make sure that you don't have an output command for the rest of the rows in that id. But you then have to resort the data again afterwards.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=RESTORED out=RESTORED_opp; 
	by ID descending ent_seq_no col_actv_code ; 
run;

data restored_2;
	set restored_opp;
	by ID;
	retain _Keep_ID 1;
	if first.id and upcase(col_actv_code) = "S" then do;
		_Keep_ID = 0;
	end;
	if _Keep_ID = 1 then output;
	if last.id then _Keep_ID = 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2019 02:20:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-a-group-based-on-a-particular-observation/m-p/571940#M161368</guid>
      <dc:creator>heffo</dc:creator>
      <dc:date>2019-07-09T02:20:03Z</dc:date>
    </item>
    <item>
      <title>Re: Delete a group based on a particular observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-a-group-based-on-a-particular-observation/m-p/571942#M161369</link>
      <description>&lt;P&gt;Using the variable names from your sample data, this would be one way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;do until (last.id);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; by id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if actv_code='S' then output_flag='N';&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;else output_flag='Y';&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;do until (last.id);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; by id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; if output_flag='Y' then output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;drop output_flag;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2019 02:29:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-a-group-based-on-a-particular-observation/m-p/571942#M161369</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-07-09T02:29:08Z</dc:date>
    </item>
    <item>
      <title>Re: Delete a group based on a particular observation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-a-group-based-on-a-particular-observation/m-p/576015#M163000</link>
      <description>&lt;P&gt;Thank you so much!! this worked. Sorry for the delay in response&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jul 2019 01:31:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-a-group-based-on-a-particular-observation/m-p/576015#M163000</guid>
      <dc:creator>TheNovice</dc:creator>
      <dc:date>2019-07-24T01:31:22Z</dc:date>
    </item>
  </channel>
</rss>

