<?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: I need to match data from 2 separate data sets based on multiple variables in a hierarchy of rul in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/I-need-to-match-data-from-2-separate-data-sets-based-on-multiple/m-p/823898#M325353</link>
    <description>&lt;P&gt;Hi Patrick,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a question... how do I avoid having matches to missing acct /acctno from rule #4?&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;</description>
    <pubDate>Mon, 18 Jul 2022 17:20:25 GMT</pubDate>
    <dc:creator>Elliott</dc:creator>
    <dc:date>2022-07-18T17:20:25Z</dc:date>
    <item>
      <title>I need to match data from 2 separate data sets based on multiple variables in a hierarchy of rules</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-to-match-data-from-2-separate-data-sets-based-on-multiple/m-p/823455#M325136</link>
      <description>&lt;P&gt;I have 2 datasets that I need to compare records to see if variable values from each match.&lt;/P&gt;
&lt;P&gt;If they match on the specific variables I assign a Rule number 1 - 6.&lt;/P&gt;
&lt;P&gt;There is a hierarchy so if the record matches on rule 1 then it does not need to be evaluated again.&lt;/P&gt;
&lt;P&gt;There will also be records that do not match that are contained in the main dataset and need to be retained.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;MATCHING HIERACHY:&lt;BR /&gt;1) pendingno = refno and lastname = last_name then rule = 1 and add recevdate (rule and recevdate are added to the data from the main_data record)&lt;BR /&gt;2) pendingno = refno then rule = 2 and add recevdate (rule and recevdate are added to the data from the main_data record)&lt;BR /&gt;3) acct = acctno and lastname = last_name then rule = 3 and add recevdate (rule and recevdate are added to the data from the main_data record)&lt;BR /&gt;4) acct = acctno then rule = 4 and add recevdate (rule and recevdate are added to the data from the main_data record)&lt;BR /&gt;5) id = sid then rule = 5 and add recevdate (rule and recevdate are added to the data from the main_data record)&lt;BR /&gt;6) lastname = last_name and firstname = first_name then rule = 6 and add recevdate (rule and recevdate are added to the data from the main_data record)&lt;/P&gt;
&lt;P&gt;There will be records that don't have any matches from the main_data they will just have blanks for rule and recevdate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have:&lt;/P&gt;
&lt;P&gt;Main Data:&lt;/P&gt;
&lt;P&gt;data work.main_data;&lt;BR /&gt;infile datalines dlm=',' dsd;&lt;BR /&gt;length lastname firstname $25 store $5 pendingno $13 id $10 acct $16;&lt;BR /&gt;input lastname firstname pendingno id acct $ assigndate :date9.;&lt;BR /&gt;format assigndate date9.;&lt;BR /&gt;datalines;&lt;/P&gt;
&lt;P&gt;JONES, JACK, 05522, A123456B85946, 079458678, 4569874589375158, 04JUN2021&lt;BR /&gt;LYONS, LOIS,&amp;nbsp; 04437, A123357B85946, 129458646, 6559874589375321, 22JAN2022&lt;BR /&gt;WILLIAMS, JOHN,&amp;nbsp;05522, A123478C25946, 379429678, 5429874589374758, 07AUG2021&lt;BR /&gt;BETZINA, ANN,&amp;nbsp; 04437, D983456B85946, 469457578, 4569874589375894, 15OCT2021&lt;BR /&gt;JOYES, JACK, &amp;nbsp; 00301, A123456B85946, 279258678, 3729874589375158, 04SEP2021&lt;BR /&gt;SAMS, MACK, &amp;nbsp; 02747, A128547B85946, 654458646, 455874589375321, 27MAY2022&lt;BR /&gt;WILLIS, JANE, &amp;nbsp; 00301, A123458X25946, 379447878, 5412345589374758, 13AUG2021&lt;BR /&gt;BETXINA, RUTH, &amp;nbsp; 04437, D983426B85946, 269453578, 4569874589387651, 25DEC2021&lt;BR /&gt;DAVIS, DAVID, &amp;nbsp; 05522, B123458X25136, 379442778, 5418445589374758, 13APR2021&lt;BR /&gt;BATHE, ROBERT, &amp;nbsp; 04437, D983716B85946, 264853578, 4569891589387657, 25MAR2022&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;Match to Data:&lt;/P&gt;
&lt;P&gt;data work.match_data;&lt;BR /&gt;infile datalines dlm=',' dsd;&lt;BR /&gt;length last_name first_name $25 refno $13 sid $10 acctno $16;&lt;BR /&gt;input last_name first_name refno sid acctno $ recevdate :date9.;&lt;BR /&gt;format recevdate date9.;&lt;BR /&gt;datalines;&lt;/P&gt;
&lt;P&gt;JONES, JACK, A123456B85946, 079458678, 4569874589375158, 05JUN2021&lt;BR /&gt;LYONS, LOIS, A123357B85946, , 6559874589375321, 23JAN2022&lt;BR /&gt;WILLIAMS, JAMES, , 379429678, 5429874589374758, 09AUG2021&lt;BR /&gt;BETZINA, ANN, D983456B85946, 469457578, 4569874589375158, 18OCT2021&lt;BR /&gt;JOYES, JACK, A123456B85946, 279258678, 3729874589375158, 07SEP2021&lt;BR /&gt;SAMS, MACK, A128547B85946, 654458646, , 28MAY2022&lt;BR /&gt;WILLS, JADE, A123458X25946, 379447878, 5412345589374758, 15AUG2021&lt;BR /&gt;BETXINA, RUTH, D983426B85946, 269453578, 4569874589387651, 27DEC2021&lt;BR /&gt;WILLIAMS, JOHN, A123478C25946, 379429678, 5429874589374758, 08AUG2021&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am at a loss as to how to do the matching with the hierarchy and get the output I need to summarize all the records from the main_data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have tried data steps and proc sql&amp;nbsp; but there is not just 1 field in both that can join the records so I cannot seem to wrap my head around the matching hierarchy and how to get the right result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then I have to take the data and summarize based on store with counts for how many records in each rule or how many mismatched.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any assistance will be greatly appreciated.&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Elliott&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2022 04:31:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-to-match-data-from-2-separate-data-sets-based-on-multiple/m-p/823455#M325136</guid>
      <dc:creator>Elliott</dc:creator>
      <dc:date>2022-07-15T04:31:30Z</dc:date>
    </item>
    <item>
      <title>Re: I need to match data from 2 separate data sets based on multiple variables in a hierarchy of rul</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-to-match-data-from-2-separate-data-sets-based-on-multiple/m-p/823463#M325140</link>
      <description>&lt;P&gt;It is not clear what you want to compare: each obs in "main_data" with each obs in "match_data", or just first obs with first obs, second with second ... ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want the later, use merge without by, rename the variables in the second dataset&amp;nbsp; and use if-then-else to set rule_number.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2022 06:02:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-to-match-data-from-2-separate-data-sets-based-on-multiple/m-p/823463#M325140</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-07-15T06:02:54Z</dc:date>
    </item>
    <item>
      <title>Re: I need to match data from 2 separate data sets based on multiple variables in a hierarchy of rul</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-to-match-data-from-2-separate-data-sets-based-on-multiple/m-p/823487#M325150</link>
      <description>&lt;P&gt;I want to evaluate every record in main_data for matches to match_data if there is a match then set rule value based on the hierarchy, so if the match is the #1 match then that is the highest level, if it is not matched to 1 then evaluate for a match to #2 etc.&amp;nbsp; so the highest level match should be retained in the rule variable.&amp;nbsp; &amp;nbsp;The only variable out of the match_data that needs to be captured on the record is the date value.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2022 10:12:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-to-match-data-from-2-separate-data-sets-based-on-multiple/m-p/823487#M325150</guid>
      <dc:creator>Elliott</dc:creator>
      <dc:date>2022-07-15T10:12:23Z</dc:date>
    </item>
    <item>
      <title>Re: I need to match data from 2 separate data sets based on multiple variables in a hierarchy of rul</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-to-match-data-from-2-separate-data-sets-based-on-multiple/m-p/823561#M325189</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/17300"&gt;@Elliott&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For each of the six rules you could create an index on dataset MATCH_DATA and then use SET statements with the KEY= option until a match is found or all rules have been applied unsuccessfully:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc datasets lib=work nolist;
modify match_data;
  index create reflast=(refno last_name);
  index create refno;
  index create acclast=(acctno last_name);
  index create acctno;
  index create sid;
  index create name=(last_name first_name);
quit;

data want(drop=last_name first_name refno sid acctno);
set main_data;
refno=pendingno;
last_name=lastname;
set match_data key=reflast/unique;
if _iorc_=0 then rule=1;
else do;
  set match_data key=refno/unique;
  if _iorc_=0 then rule=2;
  else do;
    acctno=acct;
    set match_data key=acclast/unique;
    if _iorc_=0 then rule=3;
    else do;
      set match_data key=acctno/unique;
      if _iorc_=0 then rule=4;
      else do;
        sid=id;
        set match_data key=sid/unique;
        if _iorc_=0 then rule=5;
        else do;
          first_name=firstname;
          set match_data key=name/unique;
          if _iorc_=0 then rule=6;
          else recevdate=.;
        end;
      end;
    end;
  end;
end;
_error_=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I'm not sure, though, of the performance and disk space requirements if MATCH_DATA is very large.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2022 17:33:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-to-match-data-from-2-separate-data-sets-based-on-multiple/m-p/823561#M325189</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-07-15T17:33:43Z</dc:date>
    </item>
    <item>
      <title>Re: I need to match data from 2 separate data sets based on multiple variables in a hierarchy of rul</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-to-match-data-from-2-separate-data-sets-based-on-multiple/m-p/823593#M325204</link>
      <description>&lt;P&gt;I tried this query on my sample data and it was taking so long to run on just 12&amp;nbsp; sample records I had to stop it, so I don't want to try with 10000+ records.&amp;nbsp; But Thank you, I have learned something new.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2022 23:33:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-to-match-data-from-2-separate-data-sets-based-on-multiple/m-p/823593#M325204</guid>
      <dc:creator>Elliott</dc:creator>
      <dc:date>2022-07-15T23:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: I need to match data from 2 separate data sets based on multiple variables in a hierarchy of rul</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-to-match-data-from-2-separate-data-sets-based-on-multiple/m-p/823605#M325214</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/17300"&gt;@Elliott&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I tried this query on my sample data and it was taking so long to run on just 12&amp;nbsp; sample records I had to stop it, so I don't want to try with 10000+ records.&amp;nbsp; But Thank you, I have learned something new.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If the match table got only some 10000+ records then a hash approach as below should work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.main_data;
  infile datalines dlm=',' dsd truncover;
  length lastname firstname $25 store $5 pendingno $13 id $10 acct $16;
  input lastname firstname store pendingno id acct $ assigndate :date9.;
  format assigndate date9.;
  datalines;
JONES,JACK,05522,A123456B85946,079458678,4569874589375158,04JUN2021
LYONS,LOIS,04437,A123357B85946,129458646,6559874589375321,22JAN2022
WILLIAMS,JOHN,05522,A123478C25946,379429678,5429874589374758,07AUG2021
BETZINA,ANN,04437,D983456B85946,469457578,4569874589375894,15OCT2021
JOYES,JACK,00301,A123456B85946,279258678,3729874589375158,04SEP2021
SAMS,MACK,02747,A128547B85946,654458646,455874589375321,27MAY2022
WILLIS,JANE,00301,A123458X25946,379447878,5412345589374758,13AUG2021
BETXINA,RUTH,04437,D983426B85946,269453578,4569874589387651,25DEC2021
DAVIS,DAVID,05522,B123458X25136,379442778,5418445589374758,13APR2021
BATHE,ROBERT,04437,D983716B85946,264853578,4569891589387657,25MAR2022
;

data work.match_data;
  infile datalines dlm=',' dsd truncover;
  length last_name first_name $25 refno $13 sid $10 acctno $16;
  input last_name first_name refno sid acctno $ recevdate :date9.;
  format recevdate date9.;
  datalines;
JONES,JACK,A123456B85946,079458678,4569874589375158,05JUN2021
LYONS,LOIS,A123357B85946,,6559874589375321,23JAN2022
WILLIAMS,JAMES,,379429678,5429874589374758,09AUG2021
BETZINA,ANN,D983456B85946,469457578,4569874589375158,18OCT2021
JOYES,JACK,A123456B85946,279258678,3729874589375158,07SEP2021
SAMS,MACK,A128547B85946,654458646,,28MAY2022
WILLS,JADE,A123458X25946,379447878,5412345589374758,15AUG2021
BETXINA,RUTH,D983426B85946,269453578,4569874589387651,27DEC2021
WILLIAMS,JOHN,A123478C25946,379429678,5429874589374758,08AUG2021
;

data work.v_match_data /view=work.v_match_data;
  set work.match_data;
  rename 
    refno=pendingno
    last_name=lastname
    first_name=firstname
    acctno = acct
    sid = id
    ;
run;

data want;
  if _n_=1 then
    do;
      if 0 then set work.v_match_data(keep=recevdate);
      dcl hash h_rule1(dataset:'work.v_match_data');
      h_rule1.defineKey('pendingno','lastname');
      h_rule1.defineData('recevdate');
      h_rule1.defineDone();

      dcl hash h_rule2(dataset:'work.v_match_data');
      h_rule2.defineKey('pendingno');
      h_rule2.defineData('recevdate');
      h_rule2.defineDone();
      /*** and so on ***/

    end;
  call missing(of _all_);

  set work.main_data;

  if h_rule1.find()=0 then;
  else if h_rule2.find()=0 then;
  /*** and so on ***/
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 16 Jul 2022 03:40:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-to-match-data-from-2-separate-data-sets-based-on-multiple/m-p/823605#M325214</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-07-16T03:40:24Z</dc:date>
    </item>
    <item>
      <title>Re: I need to match data from 2 separate data sets based on multiple variables in a hierarchy of rul</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-to-match-data-from-2-separate-data-sets-based-on-multiple/m-p/823721#M325279</link>
      <description>&lt;P&gt;Hi, this code works but I also need it to assign a value in a new variable called Rule, which is a 1. numeric that populates with 1 - 6 based on the matching rule.&amp;nbsp; Then I also need any that do not match from the main file to be retained and assign Rule=0;&lt;/P&gt;
&lt;P&gt;I tried a few ways to add to the code you provided but was not able to create the new variable.&amp;nbsp; What modifications are necessary to create rule assignment and retain the unmatched records?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Sun, 17 Jul 2022 14:56:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-to-match-data-from-2-separate-data-sets-based-on-multiple/m-p/823721#M325279</guid>
      <dc:creator>Elliott</dc:creator>
      <dc:date>2022-07-17T14:56:50Z</dc:date>
    </item>
    <item>
      <title>Re: I need to match data from 2 separate data sets based on multiple variables in a hierarchy of rul</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-to-match-data-from-2-separate-data-sets-based-on-multiple/m-p/823724#M325281</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1658070379672.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/73373iB6EA00AD28DE0E4C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1658070379672.png" alt="Patrick_0-1658070379672.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 17 Jul 2022 15:06:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-to-match-data-from-2-separate-data-sets-based-on-multiple/m-p/823724#M325281</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-07-17T15:06:27Z</dc:date>
    </item>
    <item>
      <title>Re: I need to match data from 2 separate data sets based on multiple variables in a hierarchy of rul</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-to-match-data-from-2-separate-data-sets-based-on-multiple/m-p/823740#M325294</link>
      <description>Thank you very much, it works perfectly.  I had tried that this morning but I must have had something else wrong because it did not work.&lt;BR /&gt;Thanks!</description>
      <pubDate>Sun, 17 Jul 2022 19:19:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-to-match-data-from-2-separate-data-sets-based-on-multiple/m-p/823740#M325294</guid>
      <dc:creator>Elliott</dc:creator>
      <dc:date>2022-07-17T19:19:45Z</dc:date>
    </item>
    <item>
      <title>Re: I need to match data from 2 separate data sets based on multiple variables in a hierarchy of rul</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-to-match-data-from-2-separate-data-sets-based-on-multiple/m-p/823898#M325353</link>
      <description>&lt;P&gt;Hi Patrick,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a question... how do I avoid having matches to missing acct /acctno from rule #4?&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;</description>
      <pubDate>Mon, 18 Jul 2022 17:20:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-to-match-data-from-2-separate-data-sets-based-on-multiple/m-p/823898#M325353</guid>
      <dc:creator>Elliott</dc:creator>
      <dc:date>2022-07-18T17:20:25Z</dc:date>
    </item>
    <item>
      <title>Re: I need to match data from 2 separate data sets based on multiple variables in a hierarchy of rul</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-to-match-data-from-2-separate-data-sets-based-on-multiple/m-p/823952#M325375</link>
      <description>&lt;P&gt;it looks like the matching on missing values is also happening with acct/lastname and id.&amp;nbsp; So my results are showing higher matches then there actually are.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have been researching hash objects for several hours and I have not been able to figure out how to exclude the matching on missing values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jul 2022 19:15:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-to-match-data-from-2-separate-data-sets-based-on-multiple/m-p/823952#M325375</guid>
      <dc:creator>Elliott</dc:creator>
      <dc:date>2022-07-18T19:15:02Z</dc:date>
    </item>
    <item>
      <title>Re: I need to match data from 2 separate data sets based on multiple variables in a hierarchy of rul</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-need-to-match-data-from-2-separate-data-sets-based-on-multiple/m-p/824012#M325395</link>
      <description>&lt;P&gt;Just exclude missings from the lookup and you will never get a match to missings.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  if _n_=1 then
    do;
      if 0 then set work.v_match_data(keep=recevdate);
      dcl hash h_rule1(dataset:'work.v_match_data');
      h_rule1.defineKey('pendingno','lastname');
      h_rule1.defineData('recevdate');
      h_rule1.defineDone();

      dcl hash h_rule2(dataset:'work.v_match_data');
      h_rule2.defineKey('pendingno');
      h_rule2.defineData('recevdate');
      h_rule2.defineDone();

      dcl hash h_rule3(dataset:'work.v_match_data');
      h_rule3.defineKey('acct','lastname');
      h_rule3.defineData('recevdate');
      h_rule3.defineDone();

      dcl hash h_rule4(dataset:'work.v_match_data(where=(not missing(acct))');
      h_rule4.defineKey('acct');
      h_rule4.defineData('recevdate');
      h_rule4.defineDone();
      /*** and so on ***/

    end;
  call missing(of _all_);

  set work.main_data;

  if h_rule1.find()=0 then rule=1;
  else if h_rule2.find()=0 then rule=2;
  else if h_rule3.find()=0 then rule=3;
  else if h_rule4.find()=0 then rule=4;
  /*** and so on ***/
  else rule=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1658196003157.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/73452i49D4932DFFC7408F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1658196003157.png" alt="Patrick_0-1658196003157.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2022 02:00:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-need-to-match-data-from-2-separate-data-sets-based-on-multiple/m-p/824012#M325395</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-07-19T02:00:10Z</dc:date>
    </item>
  </channel>
</rss>

