Please help with the code for hash join , for the below code in PROC SQL
Proc sql;
Create table test as
Select *
From dsn1 a inner join dsn2 b
On a.key1=b.key2 or a.key1a=b.key2;
Quit;
Appears a thread exists for probably what you are looking for...
https://communities.sas.com/t5/SAS-Procedures/HASH-join/m-p/112108#U112108
This paper provides example of Hash merging using 2 keys.... Refer to page 5.
http://www2.sas.com/proceedings/forum2008/029-2008.pdf
Hope this helps...
Providing sample data would help.
Below code sample assumes that the key in "dsn2" is unique. If this is not the case then you would need tag "multidata" in the hash and you would need to loop over the hash entries with the same key if there is a match.
data dsn1;
input key1 key1a @@;
source1='dsn1';
output;
datalines;
1 1 1 2 9 2 9 9
;
run;
data dsn2;
input key2 @@;
source2='dsn2';
output;
datalines;
1 2 3
;
run;
data want(drop=_rc);
set dsn1;
if _n_=1 then
do;
if 0 then set dsn2;
dcl hash h(dataset:'dsn2');
_rc=h.defineKey('key2');
_rc=h.defineData(all:'y');
_rc=h.defineDone();
end;
if h.find(key:key1)=0 then
do;
match='key1 ';
output;
end;
else if h.find(key:key1a)=0 then
do;
match='key1a';
output;
end;
run;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.