BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
theponcer
Quartz | Level 8

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. 

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

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.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

View solution in original post

2 REPLIES 2
mkeintz
PROC Star

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.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
theponcer
Quartz | Level 8

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2742 views
  • 0 likes
  • 2 in conversation