03-24-2017 04:41 PM - last edited on 03-24-2017 05:34 PM by ChrisHemedinger
Unlike in proc sql, we can join the key variables though they donnt have the common names,can this be done in hash tables?
if dataset A has key variables memberid and membername and
dataset B has key variables member_id and member_name.
in proc sql we can join on memberid=member_id and membername=memebr_name
i dont know if we have to rename before doing hash merging
03-24-2017 06:35 PM
Since one can rename when set(ting) a file, wouldn't that suffice? As for multiple keys, the hash object can take composite keys.
I would think including a rename option when setting one of the files shouldn't be a concern or am I missing something?
Art, CEO, AnalystFinder.com
03-24-2017 10:51 PM
The answer is yes.
Art has already mentioned that own could use a rename parameter. But even that isn't required.
Consder. If data sets A and B had the same name, you could do this:
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;
But let's say dataset B has varnames memid and memname. You could, if you wanted, avoid renaming as follows:
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;
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). Instead just tell it to use the memberid as the value for first key, and membername as the second. So memberid from A will be matched against memid from B, etc.
03-24-2017 11:35 PM