<?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: filtering data based on a condition in a dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/filtering-data-based-on-a-condition-in-a-dataset/m-p/644180#M192379</link>
    <description>&lt;P&gt;I think a data step is the way to go:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new;
  merge 
    check(where=(account1=account2) in=duplicate)
    check;
  by id;
  if not duplicate;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You may get a message about more than one data set in the merge having repeat of BY values, but that is OK in this case.&lt;/P&gt;</description>
    <pubDate>Thu, 30 Apr 2020 09:39:55 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2020-04-30T09:39:55Z</dc:date>
    <item>
      <title>filtering data based on a condition in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/filtering-data-based-on-a-condition-in-a-dataset/m-p/644024#M192308</link>
      <description>&lt;P&gt;Guys, I have a dataset i have and I want the output to look like this. I want the output to look like this&amp;nbsp;&lt;/P&gt;&lt;P&gt;BBB B2546 C1254&lt;BR /&gt;BBB B4578 C12456&lt;BR /&gt;BBB B7995 C14576&lt;BR /&gt;BBB B1245 C1259&lt;/P&gt;&lt;P&gt;I want to build a logic where on my ID group if there is a match of account1 and account2 then I want that ID group to be deleted (eg: AAA A2345 A2345 &amp;amp; CCC D4568 D4568) and I want to have the ID group that has all different account1 as well as account2 . I tried the code below which didn't work. I appreciate any help on this in advance.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data check;
input id $ account1 $ account2 $ ;
cards;
AAA A1234 B1456
AAA A1234 B74156
AAA A2345 A2345
BBB B2546 C1254
BBB B4578 C12456
BBB B7995 C14576
BBB B1245 C1259
CCC D4568 F1254
CCC D4568 G1458
CCC D4568 D4568
;
RUN;


PROC SQL;
	CREATE TABLE NEW AS 
	SELECT *
	FROM CHECK 
	GROUP BY ID 
	HAVING ACCCOUNT1 NOT IN (SELECT DISTINCT ACCOUNT2 FROM CHECK ); 
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Apr 2020 16:47:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/filtering-data-based-on-a-condition-in-a-dataset/m-p/644024#M192308</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2020-04-29T16:47:44Z</dc:date>
    </item>
    <item>
      <title>Re: filtering data based on a condition in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/filtering-data-based-on-a-condition-in-a-dataset/m-p/644027#M192311</link>
      <description>&lt;P&gt;Almost identical to the logic in this question&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/How-to-label-rows-that-don-t-match/m-p/643983#M192280" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/How-to-label-rows-that-don-t-match/m-p/643983#M192280&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and the solution ought to work for you as well.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 17:03:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/filtering-data-based-on-a-condition-in-a-dataset/m-p/644027#M192311</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-04-29T17:03:57Z</dc:date>
    </item>
    <item>
      <title>Re: filtering data based on a condition in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/filtering-data-based-on-a-condition-in-a-dataset/m-p/644028#M192312</link>
      <description>&lt;P&gt;please try the below code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql;
create table want as select * from check where id not in  ( select distinct id from check where account1=account2);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Apr 2020 17:06:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/filtering-data-based-on-a-condition-in-a-dataset/m-p/644028#M192312</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2020-04-29T17:06:33Z</dc:date>
    </item>
    <item>
      <title>Re: filtering data based on a condition in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/filtering-data-based-on-a-condition-in-a-dataset/m-p/644031#M192313</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12151"&gt;@Jagadishkatam&lt;/a&gt;&amp;nbsp; Hope all's well and you are safe in among the world's Covid19 fight. I'm afraid your code will miss some intricacies should the data be slightly different like:&lt;/P&gt;
&lt;P&gt;AAA A1234 B1456 &lt;BR /&gt;AAA A1234 A2345&lt;BR /&gt;AAA A2345 B74156&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, I would have to agree with you that's not the case in the sample posted by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/139130"&gt;@buddha_d&lt;/a&gt;&amp;nbsp;. Nonetheless, this is a kind of situation I would often refer back to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp; aka Mr. Perfect's teachings to never assume. On the other hand, I would also think genius&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp; would prefer a Hash check method solution as he deems a lot of Proc SQL is rather "ready meals" though fun and easy. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; We have our banters every so often as it's been a privilege to learn from these marvelous people.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Therefore, something like the below would be needed to address in full&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data check;
input id $ account1 $ account2 $ ;
cards;
AAA A1234 B1456 
AAA A1234 A2345
AAA A2345 B74156
BBB B2546 C1254
BBB B4578 C12456
BBB B7995 C14576
BBB B1245 C1259
CCC D4568 F1254
CCC D4568 G1458
CCC D4568 D4568
;
RUN;

proc sql;
create table want as
select distinct a.*
from check a left join check b
on a.account1=b.account2
group by a.id
having not n(b.account2);
quit;

proc print noobs;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.WANT" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l header" scope="col"&gt;id&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;account1&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;account2&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;BBB&lt;/TD&gt;
&lt;TD class="l data"&gt;B1245&lt;/TD&gt;
&lt;TD class="l data"&gt;C1259&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;BBB&lt;/TD&gt;
&lt;TD class="l data"&gt;B2546&lt;/TD&gt;
&lt;TD class="l data"&gt;C1254&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;BBB&lt;/TD&gt;
&lt;TD class="l data"&gt;B4578&lt;/TD&gt;
&lt;TD class="l data"&gt;C12456&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;BBB&lt;/TD&gt;
&lt;TD class="l data"&gt;B7995&lt;/TD&gt;
&lt;TD class="l data"&gt;C14576&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 29 Apr 2020 17:26:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/filtering-data-based-on-a-condition-in-a-dataset/m-p/644031#M192313</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-04-29T17:26:18Z</dc:date>
    </item>
    <item>
      <title>Re: filtering data based on a condition in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/filtering-data-based-on-a-condition-in-a-dataset/m-p/644087#M192334</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;lol love your nicknames!&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp; &amp;nbsp;Thank you!&amp;nbsp;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 21:15:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/filtering-data-based-on-a-condition-in-a-dataset/m-p/644087#M192334</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-04-29T21:15:46Z</dc:date>
    </item>
    <item>
      <title>Re: filtering data based on a condition in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/filtering-data-based-on-a-condition-in-a-dataset/m-p/644158#M192364</link>
      <description>&lt;P&gt;A data step solution:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
merge
  check (
    in=to_delete
    where=(account1 = account2)
  )
  check
;
by id;
if not to_delete;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Apr 2020 06:41:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/filtering-data-based-on-a-condition-in-a-dataset/m-p/644158#M192364</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-30T06:41:23Z</dc:date>
    </item>
    <item>
      <title>Re: filtering data based on a condition in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/filtering-data-based-on-a-condition-in-a-dataset/m-p/644180#M192379</link>
      <description>&lt;P&gt;I think a data step is the way to go:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new;
  merge 
    check(where=(account1=account2) in=duplicate)
    check;
  by id;
  if not duplicate;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You may get a message about more than one data set in the merge having repeat of BY values, but that is OK in this case.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Apr 2020 09:39:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/filtering-data-based-on-a-condition-in-a-dataset/m-p/644180#M192379</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-04-30T09:39:55Z</dc:date>
    </item>
  </channel>
</rss>

