<?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 ids based on another condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Delete-ids-based-on-another-condition/m-p/495306#M130695</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id $ location $ @@;
datalines;
1 a 1 c 1 d 1 e 2 a 2 b
2 c 2 d 2 e 3 a 3 b 3 c 3 d
4 a 4 b 4 c 4 e
;
run;

proc sql;
create table want as
select *
from have
group by id
having sum(location in ('d','e'))&amp;gt;1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 13 Sep 2018 14:27:21 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-09-13T14:27:21Z</dc:date>
    <item>
      <title>Delete ids based on another condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-ids-based-on-another-condition/m-p/495278#M130678</link>
      <description>&lt;P&gt;&amp;nbsp;I want to delete the entire row for all IDs if that ID is missing a certain value in another variable. See my example data below-- I want to delete the rows containing that ID only if they are missing location 'd' or 'e'. I think this can probably be handled easily with proc sql, but my knowledge of proc sql is pretty limited and my google results when I tried to search for answers were no help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;data have;&lt;/DIV&gt;&lt;DIV&gt;input id $ location $ @@;&lt;/DIV&gt;&lt;DIV&gt;datalines;&lt;/DIV&gt;&lt;DIV&gt;1 a 1 c 1 d 1 e 2 a 2 b&lt;/DIV&gt;&lt;DIV&gt;2 c 2 d 2 e 3 a 3 b 3 c 3 d&lt;/DIV&gt;&lt;DIV&gt;4 a 4 b 4 c 4 e&lt;/DIV&gt;&lt;DIV&gt;;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;data want;&lt;/DIV&gt;&lt;DIV&gt;input id $ location $ @@;&lt;/DIV&gt;&lt;DIV&gt;datalines;&lt;/DIV&gt;&lt;DIV&gt;1 a 1 c 1 d 1 e 2 a 2 b&lt;/DIV&gt;&lt;DIV&gt;2 c 2 d 2 e&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks in advance!&lt;/DIV&gt;</description>
      <pubDate>Thu, 13 Sep 2018 13:34:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-ids-based-on-another-condition/m-p/495278#M130678</guid>
      <dc:creator>gadnuk</dc:creator>
      <dc:date>2018-09-13T13:34:32Z</dc:date>
    </item>
    <item>
      <title>Re: Delete ids based on another condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-ids-based-on-another-condition/m-p/495284#M130683</link>
      <description>&lt;P&gt;Simplest method I could think of:&lt;/P&gt;
&lt;PRE&gt;data have;
  input id $ location $ @@;
datalines;
1 a 1 c 1 d 1 e 2 a 2 b
2 c 2 d 2 e 3 a 3 b 3 c 3 d
4 a 4 b 4 c 4 e
;
run;

proc sql;
  create table want as
  select * 
  from   have
  where  id in (select id from have where location in ("d","e"));
quit;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Sep 2018 13:59:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-ids-based-on-another-condition/m-p/495284#M130683</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-13T13:59:16Z</dc:date>
    </item>
    <item>
      <title>Re: Delete ids based on another condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-ids-based-on-another-condition/m-p/495287#M130684</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id $ location $ @@;
datalines;
1 a 1 c 1 d 1 e 2 a 2 b
2 c 2 d 2 e 3 a 3 b 3 c 3 d
4 a 4 b 4 c 4 e
;
run;

proc sql;
	CREATE TABLE want AS
	SELECT *
	FROM have
	GROUP BY id
	HAVING sum(location='d')&amp;gt;0 AND sum(location='e')&amp;gt;0
	ORDER BY id, location
;
quit;

data want2;
input id $ location $ @@;
datalines;
1 a 1 c 1 d 1 e 2 a 2 b
2 c 2 d 2 e 
;
run;

proc compare data=want compare=want2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Sep 2018 14:02:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-ids-based-on-another-condition/m-p/495287#M130684</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2018-09-13T14:02:26Z</dc:date>
    </item>
    <item>
      <title>Re: Delete ids based on another condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-ids-based-on-another-condition/m-p/495288#M130685</link>
      <description>&lt;P&gt;If your standard is that there must be both "d" and "e", then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;do until (last.id);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;by id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if location='d' then d=1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;else if location='e' then e=1;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;do until(last.id);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;by id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if d=e=1 then output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop d e;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This solution assumes that your data set is sorted by ID.&amp;nbsp; If not, run PROC SORT first.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Sep 2018 14:02:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-ids-based-on-another-condition/m-p/495288#M130685</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-09-13T14:02:50Z</dc:date>
    </item>
    <item>
      <title>Re: Delete ids based on another condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-ids-based-on-another-condition/m-p/495306#M130695</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id $ location $ @@;
datalines;
1 a 1 c 1 d 1 e 2 a 2 b
2 c 2 d 2 e 3 a 3 b 3 c 3 d
4 a 4 b 4 c 4 e
;
run;

proc sql;
create table want as
select *
from have
group by id
having sum(location in ('d','e'))&amp;gt;1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Sep 2018 14:27:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-ids-based-on-another-condition/m-p/495306#M130695</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-13T14:27:21Z</dc:date>
    </item>
    <item>
      <title>Re: Delete ids based on another condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-ids-based-on-another-condition/m-p/495407#M130740</link>
      <description>&lt;P&gt;another datastep:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id $ location $ @@;
datalines;
1 a 1 c 1 d 1 e 2 a 2 b
2 c 2 d 2 e 
;
run;
data _null_;
if _n_=1 then do;
  dcl hash H (dataset:'have',multidata:'y',ordered:'y') ;
   h.definekey  ("id") ;
   h.definedata ("id","location") ;
   h.definedone () ;
end;
do until(last.id);
set have end=lr;
by id;
if  location in ('d','e') then _iorc_+1;
if last.id ;
if _iorc_&amp;lt;2 then  rc=h.remove();
_iorc_=0;
end;
if lr then h.output(dataset:'want');
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Sep 2018 17:07:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-ids-based-on-another-condition/m-p/495407#M130740</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-13T17:07:47Z</dc:date>
    </item>
    <item>
      <title>Re: Delete ids based on another condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-ids-based-on-another-condition/m-p/495568#M130801</link>
      <description>&lt;P&gt;What if location d or e appears more than once for a given id? I think the condition&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;having max(location=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'d'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;and&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; max(location=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'e'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;)&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;would be better.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Sep 2018 03:46:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-ids-based-on-another-condition/m-p/495568#M130801</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-09-14T03:46:11Z</dc:date>
    </item>
    <item>
      <title>Re: Delete ids based on another condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-ids-based-on-another-condition/m-p/495570#M130803</link>
      <description>&lt;P&gt;fully agree Sir and always. Jealous of your extreme intelligence&amp;nbsp;&lt;img id="smileytongue" class="emoticon emoticon-smileytongue" src="https://communities.sas.com/i/smilies/16x16_smiley-tongue.png" alt="Smiley Tongue" title="Smiley Tongue" /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Sep 2018 03:57:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-ids-based-on-another-condition/m-p/495570#M130803</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-14T03:57:31Z</dc:date>
    </item>
  </channel>
</rss>

