<?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: SAS hash tables, joining on keys with different names in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-hash-tables-joining-on-keys-with-different-names/m-p/344249#M79098</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The answer is yes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art has already mentioned that own could use a rename parameter.&amp;nbsp; But even that isn't required.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consder.&amp;nbsp; If data sets A and B had the same name, you could do this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  if _n_=1 then do;
    if 0 then set B ;
    declare hash bdata (dataset:'B');
      bdata.definekey('memberid','membername');
      bdata.definedata(all:'Y');
      bdata.definedone();
  end;
  set a;
  rc=b.find();
  if rc=0;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But let's say dataset B has varnames&amp;nbsp;&amp;nbsp; memid and memname.&amp;nbsp; You could, if you wanted, avoid renaming as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  if _n_=1 then do;
    if 0 then set B ;
    declare hash bdata (dataset:'B');
      bdata.definekey('memid','memname');
      bdata.definedata(all:'Y');
      bdata.definedone();
  end;
  set a;
  rc=b.find(key:memberid,key:membername);
  if rc=0;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In other words, when using the find method for hash table b, don't let it assume it should use memid and memname (which don't exist in data set A).&amp;nbsp; Instead just tell it to use the memberid as the value for first key, and membername as the second.&amp;nbsp; So memberid from A will be matched against memid from B, etc.&lt;/P&gt;</description>
    <pubDate>Sat, 25 Mar 2017 02:51:17 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2017-03-25T02:51:17Z</dc:date>
    <item>
      <title>SAS hash tables, joining on keys with different names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-hash-tables-joining-on-keys-with-different-names/m-p/344206#M79084</link>
      <description>&lt;P&gt;Unlike in proc sql, we can join the key variables though they donnt have the common names,can this be done in hash tables?&lt;/P&gt;
&lt;P&gt;if &amp;nbsp;dataset A has key variables memberid and membername and&lt;/P&gt;
&lt;P&gt;dataset B has key variables member_id and member_name.&lt;/P&gt;
&lt;P&gt;in proc sql we can join on memberid=member_id and membername=memebr_name&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i dont know if we have to rename before doing hash merging&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2017 21:34:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-hash-tables-joining-on-keys-with-different-names/m-p/344206#M79084</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2017-03-24T21:34:31Z</dc:date>
    </item>
    <item>
      <title>Re: SAS hash tables, joining on keys with different names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-hash-tables-joining-on-keys-with-different-names/m-p/344215#M79085</link>
      <description>&lt;P&gt;Since one can rename when set(ting) a file, wouldn't that suffice? As for multiple keys, the hash object can take composite keys.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would think including a rename option when setting one of the files shouldn't be a concern or am I missing something?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2017 22:35:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-hash-tables-joining-on-keys-with-different-names/m-p/344215#M79085</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-24T22:35:43Z</dc:date>
    </item>
    <item>
      <title>Re: SAS hash tables, joining on keys with different names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-hash-tables-joining-on-keys-with-different-names/m-p/344249#M79098</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The answer is yes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art has already mentioned that own could use a rename parameter.&amp;nbsp; But even that isn't required.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consder.&amp;nbsp; If data sets A and B had the same name, you could do this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  if _n_=1 then do;
    if 0 then set B ;
    declare hash bdata (dataset:'B');
      bdata.definekey('memberid','membername');
      bdata.definedata(all:'Y');
      bdata.definedone();
  end;
  set a;
  rc=b.find();
  if rc=0;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But let's say dataset B has varnames&amp;nbsp;&amp;nbsp; memid and memname.&amp;nbsp; You could, if you wanted, avoid renaming as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  if _n_=1 then do;
    if 0 then set B ;
    declare hash bdata (dataset:'B');
      bdata.definekey('memid','memname');
      bdata.definedata(all:'Y');
      bdata.definedone();
  end;
  set a;
  rc=b.find(key:memberid,key:membername);
  if rc=0;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In other words, when using the find method for hash table b, don't let it assume it should use memid and memname (which don't exist in data set A).&amp;nbsp; Instead just tell it to use the memberid as the value for first key, and membername as the second.&amp;nbsp; So memberid from A will be matched against memid from B, etc.&lt;/P&gt;</description>
      <pubDate>Sat, 25 Mar 2017 02:51:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-hash-tables-joining-on-keys-with-different-names/m-p/344249#M79098</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-03-25T02:51:17Z</dc:date>
    </item>
    <item>
      <title>Re: SAS hash tables, joining on keys with different names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-hash-tables-joining-on-keys-with-different-names/m-p/344252#M79099</link>
      <description>Absolutely You can do. Here is the code:&lt;BR /&gt;data result;&lt;BR /&gt;if 0 then set A;&lt;BR /&gt;declare hash adata(dataset:'A');&lt;BR /&gt;adata.definekey("memberid","membername");&lt;BR /&gt;adata.definedata(all:'yes');&lt;BR /&gt;adata.definedone();&lt;BR /&gt;do until (eof);&lt;BR /&gt;set B end=eof;&lt;BR /&gt;rc=adata.find(key:member_id,key:member_name);&lt;BR /&gt;if rc eq 0 then output;&lt;BR /&gt;end;&lt;BR /&gt;drop rc member_id member_name;&lt;BR /&gt;run;</description>
      <pubDate>Sat, 25 Mar 2017 03:35:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-hash-tables-joining-on-keys-with-different-names/m-p/344252#M79099</guid>
      <dc:creator>lakshmi_74</dc:creator>
      <dc:date>2017-03-25T03:35:43Z</dc:date>
    </item>
  </channel>
</rss>

