BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello

I am using Hash method to merge data sets.

One of the data sets is in permanent library and then I get error.

 

Data tbl1;
Format date date9.;
Input Name$ date :date9. Amnt1;
cards;
A 01JAN2023 100
A 02JAN2023 150
A 03JAN2023 200
A 04JAN2023 250
B 02JAN2023 200
B 04JAN2023 300
B 06JAN2023 400
C 03JAN2023 300
C 08JAN2023 400
C 15JAN2023 500
;
run;

Data r_r.tbl2;
Input Name$ numerator W;
cards;
A 111 1000
B 222 2000
C 333 3000
D 444 4000
;
run;


data want;
set tbl1;
if _n_ = 1
then do;
declare hash r_r.tbl2 (dataset:"r_r.tbl2 (keep=Name numerator)");
r_r.tbl2.definekey("Name");
r_r.tbl2.definedata("numerator");
r_r.tbl2.definedone();
call missing(numerator);
end;
rc = r_r.tbl2.find();
drop rc;
run;

The error is :

1                                                          The SAS System                          07:19 Thursday, September 7, 2023

1          ;*';*";*/;quit;run;
2          OPTIONS PAGENO=MIN;
3          %LET _CLIENTTASKLABEL='Program (5)';
4          %LET _CLIENTPROCESSFLOWNAME='Process Flow';
5          %LET _CLIENTPROJECTPATH='';
6          %LET _CLIENTPROJECTPATHHOST='';
7          %LET _CLIENTPROJECTNAME='';
8          %LET _SASPROGRAMFILE='';
9          %LET _SASPROGRAMFILEHOST='';
10         
11         ODS _ALL_ CLOSE;
12         OPTIONS DEV=PNG;
13         GOPTIONS XPIXELS=0 YPIXELS=0;
14         FILENAME EGSR TEMP;
15         ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR
16             STYLE=HTMLBlue
17             STYLESHEET=(URL="file:///C:/Program%20Files/SASHome/SASEnterpriseGuide/7.1/Styles/HTMLBlue.css")
18             NOGTITLE
19             NOGFOOTNOTE
20             GPATH=&sasworklocation
21             ENCODING=UTF8
22             options(rolap="on")
23         ;
NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
24         
25         GOPTIONS ACCESSIBLE;
26         /***Way2***/
27         data Way2;
28         set tbl1;
29         if _n_ = 1
30         then do;
31         declare hash r_r.tbl2 (dataset:"r_r.tbl2 (keep=Name numerator)");
                        ________
                        22
                        76
32         r_r.tbl2.definekey("Name");
           __________________
           780
ERROR: DATA STEP Component Object failure.  Aborted during the COMPILATION phase.
ERROR 22-322: Expecting a name.  

ERROR 76-322: Syntax error, statement will be ignored.

ERROR 780-185: Invalid object or method name.

NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      user cpu time       0.00 seconds
      system cpu time     0.00 seconds
      memory              390.43k
      OS Memory           25768.00k
      Timestamp           09/07/2023 11:13:33 AM
      Step Count                        156  Switch Count  0
      Page Faults                       0
      Page Reclaims                     28
      Page Swaps                        0
      Voluntary Context Switches        7
2                                                          The SAS System                          07:19 Thursday, September 7, 2023

      Involuntary Context Switches      0
      Block Input Operations            0
      Block Output Operations           0
      
33         r_r.tbl2.definedata("numerator");
34         r_r.tbl2.definedone();
35         call missing(numerator);
36         end;
37         rc = r_r.tbl2.find();
38         drop rc;
39         run;
40         
41         GOPTIONS NOACCESSIBLE;
42         %LET _CLIENTTASKLABEL=;
43         %LET _CLIENTPROCESSFLOWNAME=;
44         %LET _CLIENTPROJECTPATH=;
45         %LET _CLIENTPROJECTPATHHOST=;
46         %LET _CLIENTPROJECTNAME=;
47         %LET _SASPROGRAMFILE=;
48         %LET _SASPROGRAMFILEHOST=;
49         
50         ;*';*";*/;quit;run;
51         ODS _ALL_ CLOSE;
52         
53         
54         QUIT; RUN;
55         
4 REPLIES 4
LinusH
Tourmaline | Level 20

I'm no hash programmer, but you should not use the data sets qualified name as the hash object identifier, I think you only need to specify the dataset in dataset: "option".

Data never sleeps
PeterClemmensen
Tourmaline | Level 20

The compiler expects the name of a hash object, not a SAS data set.

 

See the code below. I added the if 0 then set Statement in case the numerator variable does not exist in the PDV in the first place.

 

data want;
set tbl1;
if _n_ = 1
then do;
declare hash h (dataset:"r_r.tbl2");
h.definekey("Name");
h.definedata("numerator");
h.definedone();
if 0 then set r_r.tbl2 (keep=Name numerator);
call missing(numerator);
end;
rc = h.find();
drop rc;
run;
Ronein
Onyx | Level 15

Thanks, Sorry but I didn't understand which potential problem the statement IF 0 then should solve.

In this example below don't have numerator column  in data set r_r.tbl2 , however there is an error

Data tbl1;
Format date date9.;
Input Name$ date :date9. Amnt1;
cards;
A 01JAN2023 100
A 02JAN2023 150
A 03JAN2023 200
A 04JAN2023 250
B 02JAN2023 200
B 04JAN2023 300
B 06JAN2023 400
C 03JAN2023 300
C 08JAN2023 400
C 15JAN2023 500
;
run;

Data r_r.tbl2;
Input Name$  W;
cards;
A  1000
B  2000
C  3000
D  4000
;
run;


data want;
set tbl1;
if _n_ = 1
then do;
declare hash h (dataset:"r_r.tbl2");
h.definekey("Name");  /***Merge By VARS***/
h.definedata("numerator");/***Columns to select from r_r.tbl2***/
h.definedone();
if 0 then set r_r.tbl2 (keep=Name numerator);
/*I added the if 0 then set Statement in case the numerator variable does not exist in the PDV in the first place*/
call missing(numerator);
end;
rc = h.find();
drop rc;
run;
PeterClemmensen
Tourmaline | Level 20

First off, you will definitely get an error because there is not variable called numerator in your  r_r.tbl2 sample data.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 4 replies
  • 1293 views
  • 0 likes
  • 3 in conversation