<?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 match 2 datasets when 1 of the datasets could be matched on 2 possible variables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-match-2-datasets-when-1-of-the-datasets-could-be-matched/m-p/181447#M46222</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you everyone! Grateful. I am going to try these out when I get back to work Wednesday and will report back......&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 02 Sep 2014 07:32:13 GMT</pubDate>
    <dc:creator>pheynix</dc:creator>
    <dc:date>2014-09-02T07:32:13Z</dc:date>
    <item>
      <title>How to match 2 datasets when 1 of the datasets could be matched on 2 possible variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-match-2-datasets-when-1-of-the-datasets-could-be-matched/m-p/181440#M46215</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have wrested getting this to work in SAS for many days now.&amp;nbsp; I am about to give up and write this in a language that can handle looping a through multiple arrays at a time, but I love SAS and would much prefer to find something that works, so I am hoping someone will know how to do this in SAS...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have 2 datasets,&lt;/P&gt;&lt;P&gt;----File 1&amp;nbsp; has a unique customer identifier (let's call it "account number") and an amount in each record.&amp;nbsp; &lt;/P&gt;&lt;P&gt;----File 2&amp;nbsp; has 2 unique customer identifiers (let's call it "policy number" and "customer number") and an amount in each record.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The twist?&amp;nbsp; Account number, policy number, and customer number can all be the same number.&amp;nbsp; All 3 are always 8 characters long.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;file 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; file 2&lt;/P&gt;&lt;P&gt;--------------------------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ------------------------------------------&lt;/P&gt;&lt;P&gt;12345678&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4.50&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 12345678&amp;nbsp;&amp;nbsp; 98765432&amp;nbsp;&amp;nbsp;&amp;nbsp; 4.50&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My goal is to know:&lt;/P&gt;&lt;P&gt;1) what records are: a) on both files where the account number on file 1 equals either the policy number or the customer number on file 2. and b) the amounts are equal.&lt;/P&gt;&lt;P&gt;2) what records are: a) on both files where the account number on file 1 equals either the policy number or the customer number on file 2. and b) the amounts do not equal.&lt;/P&gt;&lt;P&gt;3) what records are only on file 1, meaning that the account number doesn't equal either the policy number or the customer number.&lt;/P&gt;&lt;P&gt;4) what records are only on file 2, meaning that neither the policy number or the customer number match the account number on file 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This makes match-merge and proc sql a nightmare of spaghetti code to filter out duplicates.&amp;nbsp; My brain hurts.&amp;nbsp; Can anyone see a way to do this in SAS?&amp;nbsp; Thank you in advance....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Sep 2014 01:10:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-match-2-datasets-when-1-of-the-datasets-could-be-matched/m-p/181440#M46215</guid>
      <dc:creator>pheynix</dc:creator>
      <dc:date>2014-09-01T01:10:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to match 2 datasets when 1 of the datasets could be matched on 2 possible variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-match-2-datasets-when-1-of-the-datasets-could-be-matched/m-p/181441#M46216</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;1) SQL join (accno = policy_no or acc_no = cust_no) and one.amt = two.amt&lt;/P&gt;&lt;P&gt;2) as above, but move the amt join criteria to a case expression in the select statement.&lt;/P&gt;&lt;P&gt;3) as above, but using a left join. Use case expression on a mandatory column in dataset 2 to see if there is a match or not.&lt;/P&gt;&lt;P&gt;4) as above, but using a right join, Or full join, in which you could fulfil all your requirements in one query.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Sep 2014 06:34:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-match-2-datasets-when-1-of-the-datasets-could-be-matched/m-p/181441#M46216</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2014-09-01T06:34:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to match 2 datasets when 1 of the datasets could be matched on 2 possible variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-match-2-datasets-when-1-of-the-datasets-could-be-matched/m-p/181442#M46217</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Analyzing, thinking at a SAS datastep.&lt;/P&gt;&lt;P&gt;- You have 4 output files being defined . &lt;/P&gt;&lt;P&gt;- The join: There is a difficult join. accountnumber (a) is to be checked to&amp;nbsp; policy number/customer number. This looks to be 3 file-join not a 2 file join.&amp;nbsp; file1 - file2a - file2b &lt;/P&gt;&lt;P&gt;-&amp;nbsp; 3 and 4 are the outer parts&amp;nbsp; 3= file1 and not file2a and not file2b&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4= not file 1 and&amp;nbsp; ( file2a or file2b)&lt;/P&gt;&lt;P&gt;-&amp;nbsp; 1,2 are of the inner part&amp;nbsp;&amp;nbsp;&amp;nbsp; file1 and ( file2a or file 2b)&amp;nbsp; &lt;/P&gt;&lt;P&gt;- The&amp;nbsp; split up on the ammmount being different or equal at the inner part is more easy.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is a twist possible "the twist":&amp;nbsp;&amp;nbsp; do you have duplicates?&amp;nbsp; can both policy number and customer number being get matched? &lt;/P&gt;&lt;P&gt;Any sample data (faked?) for doing some code? &lt;/P&gt;&lt;P&gt;What is the sizing of the data (relative small or big to your sas environment)?&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Sep 2014 06:54:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-match-2-datasets-when-1-of-the-datasets-could-be-matched/m-p/181442#M46217</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2014-09-01T06:54:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to match 2 datasets when 1 of the datasets could be matched on 2 possible variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-match-2-datasets-when-1-of-the-datasets-could-be-matched/m-p/181443#M46218</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV style="font-family: Courier New; font-size: 11pt;"&gt;&lt;STRONG style="color: #000080;"&gt;DATA&lt;/STRONG&gt;&lt;SPAN style="color: #000000;"&gt; WORK.FILE1;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;INFILE&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;CARDS&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;DLM&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;' '&lt;/SPAN&gt;; &lt;SPAN style="color: #000000;"&gt;&lt;BR /&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;ATTRIB&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; account&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;LENGTH&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;=$&lt;/SPAN&gt;&lt;STRONG style="color: #008080;"&gt;8&lt;/STRONG&gt;&lt;SPAN style="color: #000000;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; account_amount&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;LENGTH&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;=&lt;/SPAN&gt;&lt;STRONG style="color: #008080;"&gt;8&lt;/STRONG&gt;&lt;SPAN style="color: #000000;"&gt;&lt;BR /&gt;&amp;nbsp; ;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;INPUT&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; account account_amount;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;DATALINES4&lt;/SPAN&gt;; &lt;SPAN style="color: #000000;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffc0;"&gt;12345678 4.50&lt;BR /&gt;88888888 5.50&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;;;;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;STRONG style="color: #000080;"&gt;RUN&lt;/STRONG&gt;; &lt;SPAN style="color: #000000;"&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;STRONG style="color: #000080;"&gt;DATA&lt;/STRONG&gt;&lt;SPAN style="color: #000000;"&gt; WORK.FILE2;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;INFILE&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;CARDS&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;DLM&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;' '&lt;/SPAN&gt;; &lt;SPAN style="color: #000000;"&gt;&lt;BR /&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;ATTRIB&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; policy&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;LENGTH&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;=$&lt;/SPAN&gt;&lt;STRONG style="color: #008080;"&gt;8&lt;/STRONG&gt;&lt;SPAN style="color: #000000;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; customer &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;LENGTH&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;=$&lt;/SPAN&gt;&lt;STRONG style="color: #008080;"&gt;8&lt;/STRONG&gt;&lt;SPAN style="color: #000000;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; amount&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;LENGTH&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;=&lt;/SPAN&gt;&lt;STRONG style="color: #008080;"&gt;8&lt;/STRONG&gt;&lt;SPAN style="color: #000000;"&gt;&lt;BR /&gt;&amp;nbsp; ;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;INPUT&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; policy customer amount;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;DATALINES4&lt;/SPAN&gt;; &lt;SPAN style="color: #000000;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffc0;"&gt;12345678&amp;nbsp;&amp;nbsp; 98765432&amp;nbsp;&amp;nbsp;&amp;nbsp; 4.50&lt;BR /&gt;98765432&amp;nbsp;&amp;nbsp; 12345678&amp;nbsp;&amp;nbsp;&amp;nbsp; 4.30&lt;BR /&gt;99999999&amp;nbsp;&amp;nbsp; 11111111&amp;nbsp;&amp;nbsp;&amp;nbsp; 4.50&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;;;;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;STRONG style="color: #000080;"&gt;RUN&lt;/STRONG&gt;; &lt;SPAN style="color: #000000;"&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;STRONG style="color: #000080;"&gt;DATA&lt;/STRONG&gt;&lt;SPAN style="color: #000000;"&gt;&lt;BR /&gt;&amp;nbsp; WORK.RECORDS1(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;DROP&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;=account_amount)&lt;BR /&gt;&amp;nbsp; WORK.RECORDS2&lt;BR /&gt;&amp;nbsp; WORK.RECORDS4(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;DROP&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;=account_amount)&lt;BR /&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;SET&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; WORK.FILE2 &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;END&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;=_done;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&lt;BR /&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;RETAIN&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; _one &lt;/SPAN&gt;&lt;STRONG style="color: #008080;"&gt;1&lt;/STRONG&gt;&lt;SPAN style="color: #000000;"&gt; _ks &lt;/SPAN&gt;&lt;STRONG style="color: #008080;"&gt;0&lt;/STRONG&gt;; &lt;SPAN style="color: #000000;"&gt;&lt;BR /&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;DROP&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; _one _ks;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&lt;BR /&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;IF&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; _N_=&lt;/SPAN&gt;&lt;STRONG style="color: #008080;"&gt;1&lt;/STRONG&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;THEN&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;DO&lt;/SPAN&gt;; &lt;SPAN style="color: #000000;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;IF&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;STRONG style="color: #008080;"&gt;0&lt;/STRONG&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;THEN&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;SET&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; WORK.FILE1;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;DCL&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; Hash _h(DATASET:&lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;'WORK.FILE1'&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;, KEYSUM: &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;'_ks'&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;, SUMINC: &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;'_one'&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;);&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _h.defineKey(&lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;'account'&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;);&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _h.defineData(&lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;'account'&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;, &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;'account_amount'&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;);&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _h.defineDone();&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;DROP&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; account;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;END&lt;/SPAN&gt;; &lt;SPAN style="color: #000000;"&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;IF&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; _h.Find(KEY:policy) = &lt;/SPAN&gt;&lt;STRONG style="color: #008080;"&gt;0&lt;/STRONG&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;THEN&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;DO&lt;/SPAN&gt;; &lt;SPAN style="color: #000000;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;IF&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; amount = account_amount &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;THEN&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;OUTPUT&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; WORK.RECORDS1;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;ELSE&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;OUTPUT&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; WORK.RECORDS2;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;END&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;ELSE&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;IF&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; _h.Find(KEY:customer) = &lt;/SPAN&gt;&lt;STRONG style="color: #008080;"&gt;0&lt;/STRONG&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;THEN&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;DO&lt;/SPAN&gt;; &lt;SPAN style="color: #000000;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;IF&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; amount = account_amount &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;THEN&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;OUTPUT&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; WORK.RECORDS1;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;ELSE&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;OUTPUT&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; WORK.RECORDS2;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;END&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;ELSE&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;OUTPUT&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; WORK.RECORDS4;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&lt;BR /&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;IF&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; _done &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;THEN&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _h.Output(DATASET: &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;'WORK.RECORDS3(WHERE=(_ks=0))'&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;);&lt;BR /&gt;&lt;/SPAN&gt;&lt;STRONG style="color: #000080;"&gt;RUN&lt;/STRONG&gt;&lt;SPAN style="color: #000000;"&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Sep 2014 09:55:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-match-2-datasets-when-1-of-the-datasets-could-be-matched/m-p/181443#M46218</guid>
      <dc:creator>AndreyKuzenkov_SASRussia</dc:creator>
      <dc:date>2014-09-01T09:55:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to match 2 datasets when 1 of the datasets could be matched on 2 possible variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-match-2-datasets-when-1-of-the-datasets-could-be-matched/m-p/181444#M46219</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you to everyone who has responded!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes, policy number and customer number can both get matched.&amp;nbsp; There could be up to - but no more than - one entry each for both policy number and customer number in file 1, and similarly in file 2 there will be only 1 entry that has either a policy number and customer number that are the same or not the same.&amp;nbsp; The trick is to produce a match only if the amounts match AND there is a match to either policy number or customer number.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The size of the data in comparison to data size I normally deal with is small - about 18,000 records on file 1 compared to about 2,000 records on file 2. I know already there will be a lot of non-matches coming out of file 1, and I expect this.&amp;nbsp; From a business perspective, I am more concerned that each record in file 2 has a match, but I also need to know what didn't get matched from file 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am attaching sample data - 2 csv files.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In this sample data, there should be shown in the output from SAS:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) one record on file 2 (policy number field)&amp;nbsp; that matches an account number on file 1, and the amounts on each file are equal, so this is a match.&amp;nbsp; (amount of 21.17, 12345678 44445555).&lt;/P&gt;&lt;P&gt;2) one record on file 1 (account number 44445555) whose customer number happens to be the same as the first example, above, and matches to the customer number from file 2.&amp;nbsp; This same customer number just got matched (above) for 21.17, but the amount in file 1 is 125.32, so file 1's record should get treated as a mismatch.&lt;/P&gt;&lt;P&gt;3) one record on file 1 that doesn't have a match in file 2 (amount of 54.67, 22223333).&amp;nbsp; This is a mismatch.&lt;/P&gt;&lt;P&gt;4) one record on file 2 that doesn't have a match in file 1 (amount of 34.98, 11112222&amp;nbsp; 99998888).&amp;nbsp; This is a mismatch.&lt;/P&gt;&lt;P&gt;5) a case (66667777 for 98.77) where all 3 identifiers are the same and the amounts match.&amp;nbsp; This is a match.&lt;/P&gt;&lt;P&gt;6) a case (77778888) where all 3 identifiers are the same, but the amounts don't match. This s a mismatch.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note that on file 1 there will only ever be&amp;nbsp; up to -&amp;nbsp; but no more than - 1 entry that could correspond to the policy number on file 1, and likewise with regards to customer number from file 2.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Sep 2014 10:18:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-match-2-datasets-when-1-of-the-datasets-could-be-matched/m-p/181444#M46219</guid>
      <dc:creator>pheynix</dc:creator>
      <dc:date>2014-09-01T10:18:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to match 2 datasets when 1 of the datasets could be matched on 2 possible variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-match-2-datasets-when-1-of-the-datasets-could-be-matched/m-p/181445#M46220</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why don't you explore and try the suggestions first, and then get back to us if you need further assistance or for plain feed-back?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Sep 2014 10:24:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-match-2-datasets-when-1-of-the-datasets-could-be-matched/m-p/181445#M46220</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2014-09-01T10:24:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to match 2 datasets when 1 of the datasets could be matched on 2 possible variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-match-2-datasets-when-1-of-the-datasets-could-be-matched/m-p/181446#M46221</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The data borrowed above.&lt;/P&gt;&lt;PRE&gt;DATA WORK.FILE1;
&amp;nbsp; INFILE CARDS DLM=' '; 
&amp;nbsp; ATTRIB
&amp;nbsp;&amp;nbsp;&amp;nbsp; account&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LENGTH=$8
&amp;nbsp;&amp;nbsp;&amp;nbsp; account_amount&amp;nbsp; LENGTH=8
&amp;nbsp; ;
&amp;nbsp; INPUT account account_amount;
DATALINES4; 
12345678 4.50
88888888 5.50
;;;;
RUN; 

DATA WORK.FILE2;
&amp;nbsp; INFILE CARDS DLM=' '; 
&amp;nbsp; ATTRIB
&amp;nbsp;&amp;nbsp;&amp;nbsp; policy&amp;nbsp;&amp;nbsp; LENGTH=$8
&amp;nbsp;&amp;nbsp;&amp;nbsp; customer LENGTH=$8
&amp;nbsp;&amp;nbsp;&amp;nbsp; amount&amp;nbsp;&amp;nbsp; LENGTH=8
&amp;nbsp; ;
&amp;nbsp; INPUT policy customer amount;
DATALINES4; 
12345678&amp;nbsp;&amp;nbsp; 98765432&amp;nbsp;&amp;nbsp;&amp;nbsp; 4.50
98765432&amp;nbsp;&amp;nbsp; 12345678&amp;nbsp;&amp;nbsp;&amp;nbsp; 4.30
99999999&amp;nbsp;&amp;nbsp; 11111111&amp;nbsp;&amp;nbsp;&amp;nbsp; 4.50
;;;;
RUN; 
data file1;
 set file1;
 retain found 0;
run;
data one(drop=found four _account_amount) two(drop=found four _account_amount) three(keep=account account_amount) four(keep=policy customer amount);
 if _n_ eq 1 then do;
&amp;nbsp; if 0 then set file1;
&amp;nbsp; declare hash ha1(dataset:'file1');
&amp;nbsp;&amp;nbsp; ha1.definekey('account', 'account_amount');
&amp;nbsp;&amp;nbsp; ha1.definedone();

&amp;nbsp; declare hash ha2(dataset:'file1');
&amp;nbsp; declare hiter hi2('ha2');
&amp;nbsp;&amp;nbsp; ha2.definekey('account');
&amp;nbsp;&amp;nbsp; ha2.definedata(all:'y');
&amp;nbsp;&amp;nbsp; ha2.definedone();
end;
set file2 end=last;
four=1;

account=policy; _account_amount=account_amount; account_amount=amount;
if ha2.check()=0 then do;
&amp;nbsp; found=1;ha2.replace(); four=0;
&amp;nbsp; if ha1.check()=0 then output one;
&amp;nbsp;&amp;nbsp; else do; account_amount=_account_amount;output two;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end;
end;

account=customer; 
if ha2.check()=0 then do;
&amp;nbsp; found=1;ha2.replace(); four=0;
&amp;nbsp; if ha1.check()=0 then output one;
&amp;nbsp;&amp;nbsp; else do; account_amount=_account_amount;output two;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end;
end;

if&amp;nbsp; four then output four;
if last then do;
 do while(hi2.next()=0)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;;
&amp;nbsp; if not found then output three;
 end;
end;
run;



&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: xia keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Sep 2014 14:08:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-match-2-datasets-when-1-of-the-datasets-could-be-matched/m-p/181446#M46221</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-09-01T14:08:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to match 2 datasets when 1 of the datasets could be matched on 2 possible variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-match-2-datasets-when-1-of-the-datasets-could-be-matched/m-p/181447#M46222</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you everyone! Grateful. I am going to try these out when I get back to work Wednesday and will report back......&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Sep 2014 07:32:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-match-2-datasets-when-1-of-the-datasets-could-be-matched/m-p/181447#M46222</guid>
      <dc:creator>pheynix</dc:creator>
      <dc:date>2014-09-02T07:32:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to match 2 datasets when 1 of the datasets could be matched on 2 possible variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-match-2-datasets-when-1-of-the-datasets-could-be-matched/m-p/181448#M46223</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Use this methodology:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data a;&lt;BR /&gt;input accnum amount;&lt;BR /&gt;datalines;&lt;BR /&gt;12345678 4.50&lt;BR /&gt;12345679 5.50&lt;BR /&gt;12345680 6.50&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data b;&lt;BR /&gt;input plcynum custn amount;&lt;BR /&gt;datalines;&lt;BR /&gt;12345678 98765432 4.50&lt;BR /&gt;12345679 98765431 5.50&lt;BR /&gt;12345681 98765432 9.50&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table aa as select * from a,b where a.accnum=b.plcynum or a.accnum=b.custn and a.amount=b.amount;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;proc print data=aa;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Output:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Capture.JPG" class="jive-image" src="https://communities.sas.com/legacyfs/online/7264_Capture.JPG" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Sep 2014 07:56:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-match-2-datasets-when-1-of-the-datasets-could-be-matched/m-p/181448#M46223</guid>
      <dc:creator>damanaulakh88</dc:creator>
      <dc:date>2014-09-02T07:56:16Z</dc:date>
    </item>
  </channel>
</rss>

