I've been having trouble using hash tables to merge my 2 data sets. The hash table I declared has 1 key and 2 data variables.
data final_table;
if 0 then set hash_data;
if _N_=1 then do;
declare hash hashlookup (dataset:'hash_data');
hashlookup.definekey('key');
hashlookup.definedata('ABC', 'XYZ');
hashlookup.definedone();
end;
set datatabletwo;
rc = hashlookup.find(key:'key');
run;
The key is a numeric variable of the same length. I have already tried to reformat both keys to character, but the log still returns the following error message: ERROR: Type mismatch for key variable KEY at line 57 column 7.
Hope someone can help. Thanks in advance.
The problem here is that this
rc = hashlookup.find(key:'key');
looks up the string 'key'
and not the value in variable key
. Therefore, do this instead
data final_table;
if 0 then set hash_data;
if _N_=1 then do;
declare hash hashlookup (dataset:'hash_data');
hashlookup.definekey('key');
hashlookup.definedata('ABC', 'XYZ');
hashlookup.definedone();
end;
set datatabletwo;
rc = hashlookup.find();
run;