I am trying to do a hash merge. However, I keep getting an error that says "ERROR: DATA STEP Component Object failure. Aborted during the COMPILATION phase.
ERROR 557-185: Variable test is not an object."
data out_table;
set base_table;
if n=0 then set lookup_table;
if _n_ = 1 then do;
dcl hash test (dataset:'lookup_table');
test.definekey('key');
test.definedata('key','Var1');
test.definedone();
rc_test=test.find();
run;Anyone have any ideas what I am doing wrong? When I change the hash object to "test_t" it works.
Do you have a variable named TEST in either base_table or lookup_table? If so then the SAS compiler already has a use for that name, and you can't also use the name test for another purpose.
True, when you use TEST as the name of a hash object, you could think of it as a "variable". But it's a variable whose value is a pointer to an object, which in turn contains all the data items and keys loaded into the hash object. That makes it a special kind of variable (i.e. not numeric or character). And unlike other variables created within a data step, it is automatically "retained" across observations. That's why you commonly see the INSTANTIATION of a hash object inside something like an "IF _N_ then do;" group of statements.
I'll let you look up the concept of hash object instantiation (as opposed to declaration), if needed.
Also, you appear to be missing an "END:" statement after the definedone method, prior to the find method.
Do you have a variable named TEST in either base_table or lookup_table? If so then the SAS compiler already has a use for that name, and you can't also use the name test for another purpose.
True, when you use TEST as the name of a hash object, you could think of it as a "variable". But it's a variable whose value is a pointer to an object, which in turn contains all the data items and keys loaded into the hash object. That makes it a special kind of variable (i.e. not numeric or character). And unlike other variables created within a data step, it is automatically "retained" across observations. That's why you commonly see the INSTANTIATION of a hash object inside something like an "IF _N_ then do;" group of statements.
I'll let you look up the concept of hash object instantiation (as opposed to declaration), if needed.
Also, you appear to be missing an "END:" statement after the definedone method, prior to the find method.
Yup, that was the problem! I figured that was the issue, but couldn't figure out why SAS would be considering the hash table to be a variable name. Thanks for pointing me towards instantiation!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.