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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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