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
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
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.