BookmarkSubscribeRSS Feed
SAPPER
Calcite | Level 5
Hello,
I am trying to load a dataset into a hash object.
I want to use the 'DUPLICATE' option in the declare statement to replace all the duplicate keys when loading from the dataset.

But it gives me a warning: "Unrecognized or missing argument tag"
all other options in the declare statement like ORDERED work fine.
I am running this program on SAS learning guide 4.1

why is that it is not recognizing the DUPLICATE option?
Here's the code:

OPTIONS formdlim='#';
data a;
input key a b c;
datalines;
1 10 100 9
1 20 200 8
2 20 100 8
3 30 100 9
4 40 100 9
4 20 200 8
;

Data _null_;
If _N_ = 1 then do;
Declare hash H(dataset: 'work.a',duplicate:'replace', ordered:'d');
H.definekey('key');
H.definedata('a','b','c');
H.definedone();
Call missing (key,a,b,c);
end;

rc=H.OUTPUT(dataset:"work.out");
run;

proc print data =work.out;
run;

Any help on this is appreciated.
Thanks,
SAPPER
4 REPLIES 4
DanielSantos
Barite | Level 11
Are we talking about a SAS 9.2 installation?

Because this feature is not available prior that version.

Cheers from Portugal.

Daniel Santos @ www.cgd.pt
SAPPER
Calcite | Level 5
Hi Daniel,
thanks for the reply.
I am running this on 9.1.3.
Guess that explains the problem

Thanks
SAPPER.
JasonS_SAS
SAS Employee
Even though the duplicate: initialization option isn't available in SAS 9.1.3, you can load the hash object with the last obs from a group of duplicate keys. To do this, use the REPLACE method. Here is a small program:

[pre]
data a;
input key a b c;
datalines;
1 10 100 9
1 20 200 8
2 20 100 8
3 30 100 9
4 40 100 9
4 20 200 8
;

data _null_;
if _N_ = 1 then do;
declare hash H(ordered:'d');
H.definekey('key');
H.definedata('a','b','c');
H.definedone();

/* Load the hash object, getting last obs when there */
/* are duplicate keys. */
do while (^done);
set a end=done;
H.replace();
end;
end;

rc=H.output(dataset:"work.out");

stop;
run;

proc print data =work.out;
run;
[/pre]
SAPPER
Calcite | Level 5
Thanks Jason.

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
  • 2111 views
  • 0 likes
  • 3 in conversation