BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
aanan1417
Quartz | Level 8
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;
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

7 REPLIES 7
aanan1417
Quartz | Level 8
error : undeclared key symbol prodtype for hash object at line 31 column 3.
error : data step component object failure. aborted during the execution phase
Tom
Super User Tom
Super User

@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.

Kurt_Bremser
Super User

@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.

aanan1417
Quartz | Level 8
1 The SAS System 10:36 Friday, April 8, 2022

1 ;*';*";*/;quit;run;
2 OPTIONS PAGENO=MIN;
3 %LET _CLIENTTASKLABEL='Program';
4 %LET _CLIENTPROJECTPATH='';
5 %LET _CLIENTPROJECTNAME='';
6 %LET _SASPROGRAMFILE=;
7
8 ODS _ALL_ CLOSE;
9 OPTIONS DEV=ACTIVEX;
10 GOPTIONS XPIXELS=0 YPIXELS=0;
11 FILENAME EGSR TEMP;
12 ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR
13 STYLE=HtmlBlue
14 STYLESHEET=(URL="file:///C:/Program%20Files/SASHome/SASEnterpriseGuide/7.1/Styles/HtmlBlue.css")
15 NOGTITLE
16 NOGFOOTNOTE
17 GPATH=&sasworklocation
18 ENCODING=UTF8
19 options(rolap="on")
20 ;
NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
21
22 GOPTIONS ACCESSIBLE;
23
24 proc sql ;
25 create table gxhi as
26 select distinct(CHDRNUM) as Policy_no
27 ,SUMINSU
28 ,EFFDATE
29 ,PRODTYP
30 ,XCESSSI
31 from SAS0416.GXHI_&yr&mon
32 where DTETRM ne EFFDATE
33 order by Policy_no, PRODTYP , EFFDATE desc;
NOTE: Table WORK.GXHI created, with 40384382 rows and 5 columns.

34
NOTE: PROCEDURE SQL used (Total process time):
real time 1:07.09
cpu time 1:39.03

35 data gxhi1;

36 set gxhi;
37 PRODTYP1 = input(PRODTYP, best32.);
38 drop PRODTYP;
39 rename PRODTYP1=PRODTYP;
40
41 run;

NOTE: There were 40384382 observations read from the data set WORK.GXHI.
NOTE: The data set WORK.GXHI1 has 40384382 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 7.03 seconds
cpu time 6.98 seconds


42
2 The SAS System 10:36 Friday, April 8, 2022

43 data PROD_POL_MAPPING;
44 set sas0416.PROD_POL_MAPPING;
45 run;

NOTE: There were 140 observations read from the data set SAS0416.PROD_POL_MAPPING.
NOTE: The data set WORK.PROD_POL_MAPPING has 140 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.01 seconds


46
47 data gxhi2; /* create this new dataset */
48 set gxhi1; /* read all variables from this dataset */
49 if _n_ = 1 /* in the first iteration of the data step */
50 then do;
51 /* define a hash object */
52 declare hash p (dataset:"prod_pol_mapping (keep=product_type rename=(product_type=prodtype))");
53 /* define the object from a dataset where we keep one variable and rename it, so the names fit */
54 p.definekey("prodtype"); /* define the single variable as key */
55 p.definedata("prodtype"); /* and also as data, this reduces the memory footprint of the object */
56 p.definedone(); /* definition complete */
57 end;
58 if p.check() = 0; /* the check method returns a zero when an entry is found */
59 run;

ERROR: Undeclared key symbol prodtype for hash object at line 56 column 3.
ERROR: DATA STEP Component Object failure. Aborted during the EXECUTION phase.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 1 observations read from the data set WORK.GXHI1.
WARNING: The data set WORK.GXHI2 may be incomplete. When this step was stopped there were 0 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.04 seconds
cpu time 0.03 seconds
Kurt_Bremser
Super User

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.

Ksharp
Super User
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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 614 views
  • 2 likes
  • 4 in conversation