<?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 find if there's a match between 2 columns with group by in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-if-there-s-a-match-between-2-columns-with-group-by/m-p/822331#M324720</link>
    <description>&lt;P&gt;Alternatively&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tempp;
length first last col_a col_b $10;
input first last col_a col_b;
datalines;
jone smith aa bb
jone smith cc bb
jone smith dd cc
jone smith ee aa
peter paul zz dd
peter paul pp dd
peter paul aa cc
peter paul bb aa
;
run;

data want;

   if _N_ = 1 then do;
      dcl hash h(dataset : "tempp", multidata : 'Y');
      h.definekey('first', 'last', 'col_b');
      h.definedone();
   end;

   set tempp;
   by first last;

   if h.check(key : first, key : last, key : col_a) = 0;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Result&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;first  last   col_a  col_b
jone   smith  aa     bb
jone   smith  cc     bb
peter  paul   aa     cc&lt;/PRE&gt;</description>
    <pubDate>Fri, 08 Jul 2022 18:22:02 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2022-07-08T18:22:02Z</dc:date>
    <item>
      <title>How to find if there's a match between 2 columns with group by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-if-there-s-a-match-between-2-columns-with-group-by/m-p/822295#M324707</link>
      <description>&lt;P&gt;Hello, I need help finding a way to identify if there's a match between 2 columns with a group by criteria. For example&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tempp;
length first last col_a col_b $10;
input first last col_a col_b;
datalines;
jone smith aa bb
jone smith cc bb
jone smith dd cc
jone smith ee aa
peter paul zz dd
peter paul pp dd
peter paul aa cc
peter paul bb aa
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 239px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/73066iE5C36A05080FA6DF/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;We see that for jone smith, there's a matching 'aa' in col_a and col_b, same for peter paul. Is there a way to search within a group (here it's by person) and see if there's a match between 2 columns?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance for any help!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 15:09:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-if-there-s-a-match-between-2-columns-with-group-by/m-p/822295#M324707</guid>
      <dc:creator>siare1023</dc:creator>
      <dc:date>2022-07-08T15:09:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to find if there's a match between 2 columns with group by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-if-there-s-a-match-between-2-columns-with-group-by/m-p/822316#M324715</link>
      <description>&lt;P&gt;There's also a second one for Jone?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tempp;
length first last col_a col_b $10;
input first last col_a col_b;
datalines;
jone smith aa bb
jone smith cc bb
jone smith dd cc
jone smith ee aa
peter paul zz dd
peter paul pp dd
peter paul aa cc
peter paul bb aa
;
run;

proc sql;
	create table 	want as
		select
					t1.first,
					t1.last,
					t1.col_a,
					t2.col_b
		from
					tempp as t1
						inner join
					tempp as t2
							on 	t1.first = t2.first 	and
								t1.last = t2.last		and
								t1.col_a = t2.col_b;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="maguiremq_0-1657297278329.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/73073iDC9B55F15C9D1233/image-size/medium?v=v2&amp;amp;px=400" role="button" title="maguiremq_0-1657297278329.png" alt="maguiremq_0-1657297278329.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Is that what you wanted?&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 16:21:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-if-there-s-a-match-between-2-columns-with-group-by/m-p/822316#M324715</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2022-07-08T16:21:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to find if there's a match between 2 columns with group by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-if-there-s-a-match-between-2-columns-with-group-by/m-p/822329#M324718</link>
      <description>&lt;P&gt;Wow I didn't even consider inner joining with itself... I can definitely work with this, thank you so much!! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 18:15:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-if-there-s-a-match-between-2-columns-with-group-by/m-p/822329#M324718</guid>
      <dc:creator>siare1023</dc:creator>
      <dc:date>2022-07-08T18:15:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to find if there's a match between 2 columns with group by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-if-there-s-a-match-between-2-columns-with-group-by/m-p/822331#M324720</link>
      <description>&lt;P&gt;Alternatively&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tempp;
length first last col_a col_b $10;
input first last col_a col_b;
datalines;
jone smith aa bb
jone smith cc bb
jone smith dd cc
jone smith ee aa
peter paul zz dd
peter paul pp dd
peter paul aa cc
peter paul bb aa
;
run;

data want;

   if _N_ = 1 then do;
      dcl hash h(dataset : "tempp", multidata : 'Y');
      h.definekey('first', 'last', 'col_b');
      h.definedone();
   end;

   set tempp;
   by first last;

   if h.check(key : first, key : last, key : col_a) = 0;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Result&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;first  last   col_a  col_b
jone   smith  aa     bb
jone   smith  cc     bb
peter  paul   aa     cc&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Jul 2022 18:22:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-if-there-s-a-match-between-2-columns-with-group-by/m-p/822331#M324720</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-07-08T18:22:02Z</dc:date>
    </item>
  </channel>
</rss>

