data gxhi2;
set gxhi1;
if _n_ = 1
then do;
declare hash p (dataset:"prod_pol_mapping (keep=product_type rename=(product_type=prodtype))");
p.definekey("prodtype");
p.definedata("prodtype");
p.definedone();
end;
if p.check() = 0;
run;
I made a mistake in naming the variable. It should be prodtyp instead of prodtype. Please change that wherever it appears.
Background: since a variable named prodtype has never been defined in the PDV before the hash definition, it can't be used at this point (hash definition happens during runtime, and then no variables can be added to the PDV). If one needs to create new variables through a hash, they must be defined first (usually with a LENGTH statement), but here I use an existing variable coming in from the SET, and the name must match properly.
@aanan1417 wrote:
error : undeclared key symbol prodtype for hash object at line 31 column 3.
error : data step component object failure. aborted during the execution phase
That means you never defined the variable PRODTYPE in the data step.
When you setup the hash object definition with DEFINEKEY() and DEFINEDATA() you are just passing in a string with the NAME of the variable. When the hash actually begins to run those variables need to exist. But PRODTYPE is not in the input dataset gxhi1 and there is no other code in the data step to create it.
Your CHECK() function call will not work either if there is no such variable. If you want to use a different variable in the CHECK() call then specify the KEY value to use in the function call.
@Tom the mistake was by me, posted in another thread. Somehow the back of my mind translated the (most possibly German) abbreviation prodtyp to the English prodtype. Using prodtyp instead of prodtype in the RENAME= and DEFINE statements will fix it, as that variable is defined through the dataset in the SET statement.
Please post the complete log (including all code and messages).
I made a mistake in naming the variable. It should be prodtyp instead of prodtype. Please change that wherever it appears.
Background: since a variable named prodtype has never been defined in the PDV before the hash definition, it can't be used at this point (hash definition happens during runtime, and then no variables can be added to the PDV). If one needs to create new variables through a hash, they must be defined first (usually with a LENGTH statement), but here I use an existing variable coming in from the SET, and the name must match properly.
data gxhi2; set gxhi1; if _n_ = 1 then do; if 0 then set prod_pol_mapping (keep=product_type rename=(product_type=prodtype)) ; declare hash p (dataset:"prod_pol_mapping (keep=product_type rename=(product_type=prodtype))"); p.definekey("prodtype"); p.definedata("prodtype"); p.definedone(); end; if p.check() = 0; run;
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.