<?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: How to chose items that don't match in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-chose-items-that-don-t-match/m-p/639950#M190453</link>
    <description>&lt;P&gt;Sorry. better do it by a data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input @1 id 1. @3 state $3.;
datalines;
1 vic
1 nsw
2 nsw
2 qld
3 wa
;
run;

data pwd;
input @1 pwd 2. @4 id 1. @6 state $3.;
datalines;
11 1 nsw
12 1 vic
13 2 nsw
14 2 vic
15 3 wa
16 3 qld
17 3 sa
;
run;

proc sort data=test; by id state; run;
proc sort data=pwd;  by id state; run;
data want;
merge test (in=in1)
          pwd (in=in2);
 by id state;  
     if  not (in1 and in2);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 15 Apr 2020 03:04:14 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2020-04-15T03:04:14Z</dc:date>
    <item>
      <title>How to chose items that don't match</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-chose-items-that-don-t-match/m-p/639936#M190445</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code below identifies id and state where there is a match in the combinations but how does one do the inverse and find the ids and state combinations from the first table that don't have a corresponding match in the second table?&amp;nbsp; I've tried where id = id and state not = state, tried a correlated subquery and a range of coding attempts that give me errors.&amp;nbsp; I have a work around that works at present (that relies on me knowing all available values, concatanating them and doing a case statement with a find function) but I'd like to be able to write this dynamically as there are a host of uses for this in my area.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's an example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; test;&lt;/P&gt;&lt;P&gt;input @&lt;STRONG&gt;1&lt;/STRONG&gt; id &lt;STRONG&gt;1.&lt;/STRONG&gt; @&lt;STRONG&gt;3&lt;/STRONG&gt; state $3.;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1 vic&lt;/P&gt;&lt;P&gt;1 nsw&lt;/P&gt;&lt;P&gt;2 nsw&lt;/P&gt;&lt;P&gt;2 qld&lt;/P&gt;&lt;P&gt;3 wa&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; pwd;&lt;/P&gt;&lt;P&gt;input @&lt;STRONG&gt;1&lt;/STRONG&gt; pwd &lt;STRONG&gt;2.&lt;/STRONG&gt; @&lt;STRONG&gt;4&lt;/STRONG&gt; id &lt;STRONG&gt;1.&lt;/STRONG&gt; @&lt;STRONG&gt;6&lt;/STRONG&gt; state $3.;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;11 1 nsw&lt;/P&gt;&lt;P&gt;12 1 vic&lt;/P&gt;&lt;P&gt;13 2 nsw&lt;/P&gt;&lt;P&gt;14 2 vic&lt;/P&gt;&lt;P&gt;15 3 wa&lt;/P&gt;&lt;P&gt;16 3 qld&lt;/P&gt;&lt;P&gt;17 3 sa&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt; &lt;STRONG&gt;&lt;EM&gt;sql&lt;/EM&gt;&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;select * from work.pwd as t1&lt;/P&gt;&lt;P&gt;inner join work.test as t2&amp;nbsp;on t1.id=t2.id and t1.state=t2.state;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This gives me all the matching combinations.&amp;nbsp; However what I'm after is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id state&lt;/P&gt;&lt;P&gt;2 vic&lt;/P&gt;&lt;P&gt;3 qld&lt;/P&gt;&lt;P&gt;3 sa&lt;/P&gt;&lt;P&gt;(i.e. all non-matching combinations).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Not fussed if this is done in a data step or proc sql but would prefer sql as my team is mainly a sql shop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Gordon&lt;/P&gt;</description>
      <pubDate>Wed, 15 Apr 2020 01:35:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-chose-items-that-don-t-match/m-p/639936#M190445</guid>
      <dc:creator>gordononline</dc:creator>
      <dc:date>2020-04-15T01:35:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to chose items that don't match</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-chose-items-that-don-t-match/m-p/639940#M190447</link>
      <description>&lt;P&gt;Just add one step more using sql:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table matched as          /* line added to your code */
select * from work.pwd as t1
inner join work.test as t2 on t1.id=t2.id and t1.state=t2.state;
&lt;BR /&gt;select * from work.test as t1&lt;BR /&gt;where not exists &lt;BR /&gt;(select * from work.matched as t2&lt;BR /&gt;  where t1.id=t2.id and t1.state=t2.state);&lt;BR /&gt;quit;&lt;BR /&gt;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Apr 2020 02:43:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-chose-items-that-don-t-match/m-p/639940#M190447</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-04-15T02:43:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to chose items that don't match</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-chose-items-that-don-t-match/m-p/639943#M190449</link>
      <description>Thanks but this doesn't seem to work as SAS proc sql doesn't have 'outer join' as a statement. Likely T-SQL allows this though.&lt;BR /&gt;&lt;BR /&gt;Doug</description>
      <pubDate>Wed, 15 Apr 2020 02:32:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-chose-items-that-don-t-match/m-p/639943#M190449</guid>
      <dc:creator>gordononline</dc:creator>
      <dc:date>2020-04-15T02:32:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to chose items that don't match</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-chose-items-that-don-t-match/m-p/639944#M190450</link>
      <description>I have edited my code</description>
      <pubDate>Wed, 15 Apr 2020 02:44:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-chose-items-that-don-t-match/m-p/639944#M190450</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-04-15T02:44:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to chose items that don't match</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-chose-items-that-don-t-match/m-p/639950#M190453</link>
      <description>&lt;P&gt;Sorry. better do it by a data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input @1 id 1. @3 state $3.;
datalines;
1 vic
1 nsw
2 nsw
2 qld
3 wa
;
run;

data pwd;
input @1 pwd 2. @4 id 1. @6 state $3.;
datalines;
11 1 nsw
12 1 vic
13 2 nsw
14 2 vic
15 3 wa
16 3 qld
17 3 sa
;
run;

proc sort data=test; by id state; run;
proc sort data=pwd;  by id state; run;
data want;
merge test (in=in1)
          pwd (in=in2);
 by id state;  
     if  not (in1 and in2);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Apr 2020 03:04:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-chose-items-that-don-t-match/m-p/639950#M190453</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-04-15T03:04:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to chose items that don't match</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-chose-items-that-don-t-match/m-p/639998#M190493</link>
      <description>&lt;P&gt;You can create both matched and unmatched items in the same data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=test; by id state; run;
proc sort data=pwd;  by id state; run;

data matched unmatched;
merge test (in=in1)
      pwd (in=in2);
 by id state;  
     if (in1 and in2) then output matched;
     else output unmatched;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Apr 2020 07:06:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-chose-items-that-don-t-match/m-p/639998#M190493</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-04-15T07:06:38Z</dc:date>
    </item>
  </channel>
</rss>

