<?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: Excluding all records of the same ID if any record with that ID meets two conditions in PROC SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Excluding-all-records-of-the-same-ID-if-any-record-with-that-ID/m-p/786069#M250929</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/409956"&gt;@alicezwang96&lt;/a&gt;&amp;nbsp; -&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input ID $    Pet &amp;amp; $15.;
cards;
01    Dog
01    Cat
01    Parrot
01    Guinea Pig
02    Dog
02    Guinea Pig
03    Parrot
;


proc sql;
 create table want as
 select *
 from have
 group by id
 having count(distinct case when pet in ('Dog','Cat') then pet else ' ' end)&amp;lt;2;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 14 Dec 2021 21:56:06 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2021-12-14T21:56:06Z</dc:date>
    <item>
      <title>Excluding all records of the same ID if any record with that ID meets two conditions in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Excluding-all-records-of-the-same-ID-if-any-record-with-that-ID/m-p/786053#M250915</link>
      <description>&lt;DIV class=""&gt;&lt;P&gt;I have a table that looks like this:&lt;/P&gt;&lt;PRE&gt;ID    Pet
01    Dog
01    Cat
01    Parrot
01    Guinea Pig
02    Dog
02    Guinea Pig
03    Parrot&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If an ID has a dog and a cat, then I want to exclude ALL records for that ID, regardless of what other animals they have. So my output table would look like:&lt;/P&gt;&lt;PRE&gt;ID    Pet
02    Dog
02    Guinea Pig
03    Parrot&lt;/PRE&gt;&lt;P&gt;This is the query that I've tried:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;PROC SQL;
CREAT TABLE new_table AS
SELECT * from Pets a
WHERE NOT EXISTS (SELECT *
                  FROM Pets b
                  WHERE b.ID = a.ID
                  AND b.ID = "Dog"
                  AND b.ID = "Guinea Cat"));
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This doesn't seem to be working and isn't actually filtering anything out.&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 14 Dec 2021 21:09:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Excluding-all-records-of-the-same-ID-if-any-record-with-that-ID/m-p/786053#M250915</guid>
      <dc:creator>alicezwang96</dc:creator>
      <dc:date>2021-12-14T21:09:21Z</dc:date>
    </item>
    <item>
      <title>Re: Excluding all records of the same ID if any record with that ID meets two conditions in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Excluding-all-records-of-the-same-ID-if-any-record-with-that-ID/m-p/786056#M250918</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;b.ID = "Dog" AND b.ID = "Guinea Cat"&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is always false, the value of ID can't be both "Dog" and "Guinea Cat". Furthermore, variable ID contains numbers, while variable PET contains the types of animals, but even if you replaced ID with PET in the above command, it still won't work. So that's two reasons why this won't work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would do the following (UNTESTED CODE)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have out=have_t prefix=pet;
    by id;
    var pet;
run;
data want;
    set have_t;
    if whichc('Dog',of pet:)&amp;gt;0 and whichc('Cat',of pet:)&amp;gt;0 then delete;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This doesn't quite produce the exact output you want, it produces a transposed output. You could always transpose WANT to get the exact layout you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Dec 2021 21:22:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Excluding-all-records-of-the-same-ID-if-any-record-with-that-ID/m-p/786056#M250918</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-14T21:22:06Z</dc:date>
    </item>
    <item>
      <title>Re: Excluding all records of the same ID if any record with that ID meets two conditions in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Excluding-all-records-of-the-same-ID-if-any-record-with-that-ID/m-p/786069#M250929</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/409956"&gt;@alicezwang96&lt;/a&gt;&amp;nbsp; -&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input ID $    Pet &amp;amp; $15.;
cards;
01    Dog
01    Cat
01    Parrot
01    Guinea Pig
02    Dog
02    Guinea Pig
03    Parrot
;


proc sql;
 create table want as
 select *
 from have
 group by id
 having count(distinct case when pet in ('Dog','Cat') then pet else ' ' end)&amp;lt;2;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Dec 2021 21:56:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Excluding-all-records-of-the-same-ID-if-any-record-with-that-ID/m-p/786069#M250929</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2021-12-14T21:56:06Z</dc:date>
    </item>
  </channel>
</rss>

