<?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: Match 2 out of 3 conditions? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623195#M183421</link>
    <description>&lt;P&gt;Try using the + sign instead of the sum function.&lt;/P&gt;
&lt;P&gt;SQL is pickier than a data step,&lt;/P&gt;
&lt;P&gt;Otherwise, try my syntax.&lt;/P&gt;</description>
    <pubDate>Fri, 07 Feb 2020 22:20:52 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2020-02-07T22:20:52Z</dc:date>
    <item>
      <title>Match 2 out of 3 conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623176#M183407</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table want as 
	select lab as a
	       park as b
	from a b 
	where ((a.first_name=b.first_name and a.last_name=b.last_name)+
			(a.first_name=b.first_name and a.birthdate=b.DOB)+
	         (a.last_name=b.last_name and b.DOB)) &amp;gt;1 ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dataset A with 50 variables with 2000 rows, dataset B with 10 variables with 300 rows.&amp;nbsp; Both dataset have same name, birthdate and sex variables.&amp;nbsp;&amp;nbsp;As long as these two dataset have&amp;nbsp;same (name and&amp;nbsp;birthdate) or same&amp;nbsp;(sex and&amp;nbsp;name) or same (sex and birthday)&amp;nbsp;have same value, I link those data together first.&amp;nbsp; Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 22:40:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623176#M183407</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2020-02-07T22:40:31Z</dc:date>
    </item>
    <item>
      <title>Re: Match 2 out of 3 conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623183#M183411</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
&amp;nbsp; select A.*
  from A,B
&amp;nbsp; where (A.NAME=B.NAME and A.DATE = B.DATE)
 &amp;nbsp; &amp;nbsp; or&amp;nbsp;(A.NAME=B.NAME and A.SEX  = B.SEX )
&amp;nbsp;   &amp;nbsp;or (A.DATE=B.DATE and A.SEX  = B.SEX );

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 22:02:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623183#M183411</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-02-07T22:02:26Z</dc:date>
    </item>
    <item>
      <title>Re: Match 2 out of 3 conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623186#M183413</link>
      <description>&lt;P&gt;I use VERY similar code, some how the result dataset only comes with dataset A variables, no dataset B variables.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 22:08:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623186#M183413</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2020-02-07T22:08:05Z</dc:date>
    </item>
    <item>
      <title>Re: Match 2 out of 3 conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623188#M183415</link>
      <description>&lt;P&gt;SAS evaluates boolean expressions as 1 or 0.&amp;nbsp; So just sum them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where sum( a.name=b.name, a.bday=b.bday, a.sex=b.sex ) &amp;nbsp;&amp;gt;&amp;nbsp;1&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Feb 2020 22:09:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623188#M183415</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-07T22:09:21Z</dc:date>
    </item>
    <item>
      <title>Re: Match 2 out of 3 conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623191#M183417</link>
      <description>&lt;P&gt;A dataset can only one variable of a given name.&amp;nbsp; So if you do select a.NAME,b.NAME you don't get two name variables, just one.&amp;nbsp; In particular PROC SQL will pick the first one and ignore the second one.&amp;nbsp; You need to give them unique names.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 22:11:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623191#M183417</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-07T22:11:14Z</dc:date>
    </item>
    <item>
      <title>Re: Match 2 out of 3 conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623192#M183418</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Error: Summary functions are restricted to the SELECT and HAVING clauses only&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 22:16:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623192#M183418</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2020-02-07T22:16:47Z</dc:date>
    </item>
    <item>
      <title>Re: Match 2 out of 3 conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623194#M183420</link>
      <description>&lt;P&gt;I would advise joining by all three conditions first as that is the most reliable. The next most reliable would be birth date and name followed by sex and name as you have described. SQL is a good choice for this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table want as
  select  A.name
            ,A.birthdate
            ,A.sex
            ,B.name
            ,B.birthdate
            ,B.sex
            ,'1 Name, Birthdate, Sex' as jointype length = 20
  from A
  left join B
  on A.name = B.name
  and A.birthdate = B.birthdate
  and A.sex = B.sex
  union all
  select  A.name
            ,A.birthdate
            ,A.sex
            ,B.name
            ,B.birthdate
            ,B.sex
            ,'2 Name, Birthdate' as jointype length = 20
  from A
  left join B
  on A.name = B.name
  and A.birthdate = B.birthdate
  union all
  select  A.name
            ,A.birthdate
            ,A.sex
            ,B.name
            ,B.birthdate
            ,B.sex
            ,'3 Name, Sex' as jointype length = 20
  from A
  left join B
  on A.name = B.name
  and A.sex = B.sex
  order by Name, jointype
  ;
quit;
   &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You will end up with multiple join types for each name so then just choose the one with the lowest number.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 22:19:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623194#M183420</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2020-02-07T22:19:30Z</dc:date>
    </item>
    <item>
      <title>Re: Match 2 out of 3 conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623195#M183421</link>
      <description>&lt;P&gt;Try using the + sign instead of the sum function.&lt;/P&gt;
&lt;P&gt;SQL is pickier than a data step,&lt;/P&gt;
&lt;P&gt;Otherwise, try my syntax.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 22:20:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623195#M183421</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-02-07T22:20:52Z</dc:date>
    </item>
    <item>
      <title>Re: Match 2 out of 3 conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623196#M183422</link>
      <description>&lt;P&gt;I still only get set 1 variables.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 22:22:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623196#M183422</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2020-02-07T22:22:45Z</dc:date>
    </item>
    <item>
      <title>Re: Match 2 out of 3 conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623197#M183423</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Error: Summary functions are restricted to the SELECT and HAVING clauses only&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Don't use SQL aggregate functions. Use the SAS sum(,) function like in the code I posted.&amp;nbsp; Or just type the + operators instead.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 22:24:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623197#M183423</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-07T22:24:21Z</dc:date>
    </item>
    <item>
      <title>Re: Match 2 out of 3 conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623198#M183424</link>
      <description>&lt;P&gt;sum didn't help,&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 22:26:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623198#M183424</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2020-02-07T22:26:37Z</dc:date>
    </item>
    <item>
      <title>Re: Match 2 out of 3 conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623201#M183426</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select a.name as nameA
     , b.name as nameB
...&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Feb 2020 22:30:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623201#M183426</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-07T22:30:38Z</dc:date>
    </item>
    <item>
      <title>Re: Match 2 out of 3 conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623202#M183427</link>
      <description>&lt;P&gt;I have been trying use sum or +, I still only get dataset 1 variables.&amp;nbsp; Not including dataset 2 variables.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 22:32:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623202#M183427</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2020-02-07T22:32:08Z</dc:date>
    </item>
    <item>
      <title>Re: Match 2 out of 3 conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623206#M183428</link>
      <description>&lt;P&gt;Could someone let me know where my code went wrong, I keep getting dataset a variables.&amp;nbsp; That's it.&amp;nbsp; Where is the set b?&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 22:41:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623206#M183428</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2020-02-07T22:41:54Z</dc:date>
    </item>
    <item>
      <title>Re: Match 2 out of 3 conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623214#M183433</link>
      <description>&lt;P&gt;Post the code.&amp;nbsp; Or Post the lines from the SAS log. Make sure to use the Insert Code or Insert SAS Code button.&lt;/P&gt;
&lt;P&gt;Your original code was only referencing one dataset named A but assigning the alias B to it because you wrote&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;from A B
where ...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To see that type of mistake in action try this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a b; 
  set sashelp.class; 
  if sex='M' then output a ;
  else output b;
run;

proc sql ;
select a.*,b.*
from a b
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Instead use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;from A , B
where&amp;nbsp;...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;from A 
inner join B
on ....&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Feb 2020 01:58:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623214#M183433</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-08T01:58:04Z</dc:date>
    </item>
    <item>
      <title>Re: Match 2 out of 3 conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623226#M183439</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Error: Summary functions are restricted to the SELECT and HAVING clauses only&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Since your example code at the start of this thread did not include any summary functions then perhaps it is time to show the actual code you are using when generating errors.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 23:50:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623226#M183439</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-02-07T23:50:41Z</dc:date>
    </item>
    <item>
      <title>Re: Match 2 out of 3 conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623247#M183444</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp; Could someone let me know where my code went wrong, I keep getting dataset a variables.&amp;nbsp; That's it.&amp;nbsp; Where is the set b?&lt;/EM&gt;&lt;/P&gt;
&lt;DIV class="lia-quilt-row lia-quilt-row-forum-message-footer"&gt;
&lt;DIV class="lia-quilt-column lia-quilt-column-04 lia-quilt-column-left lia-quilt-column-footer-left"&gt;
&lt;DIV class="lia-quilt-column-alley lia-quilt-column-alley-left"&gt;
&lt;DIV class="lia-message-notify lia-component-report-abuse"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="lia-message-notify lia-component-report-abuse"&gt;1. The reason had already been explained to you, and you also have notes in your log explaining the reason: rename your duplicate variables&lt;/DIV&gt;
&lt;DIV class="lia-message-notify lia-component-report-abuse"&gt;select A.*, B.DUPNAME as DUPNAME_B&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Sat, 08 Feb 2020 01:27:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Match-2-out-of-3-conditions/m-p/623247#M183444</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-02-08T01:27:53Z</dc:date>
    </item>
  </channel>
</rss>

