Help using Base SAS procedures

how to use hash with duplicate key

Reply
Contributor
Posts: 35

how to use hash with duplicate key

Hello everyone.

C1 was created by using proc sql, C2 was created by using hash.because there are duplicate when I try to use hash.the method 1 can get desired result but method 2 can not.

any suggestion for method 2(use hash)?

data a;

input x y;

cards;

1 2

2 4

3 6

;

data b;

input x a $;

cards;

1 a

2 b

2 c

3 d

3 e

4 f

;

desired result:

x    y    a

1    2    a

2    4    c

2    4    b

3    6    e

3    6    d

method 1Smiley Sadthis works)

proc sql noprint;

create table C1 as

select a.*,b.a

from a

left join

b

on a.x=b.x

;

quit;

method 2Smiley Sadthis doesn't work)

data C2;

dcl hash h (dataset:'b');

rc=h.definekey('x');

rc=h.definedata('a');

rc=h.definedone();

do until (eof);

set a end=eof;

a='';

rc=h.find();

output;

end;

stop;

run;

Thanks

George

Respected Advisor
Posts: 3,124

how to use hash with duplicate key

First, are you running SAS 9.2 or above?

Contributor
Posts: 35

how to use hash with duplicate key

SAS 9.1.3

Respected Advisor
Posts: 3,124

how to use hash with duplicate key

That explains it. SAS hash does not support duplicate key until 9.2

http://support.sas.com/documentation/cdl/en/whatsnew/62580/HTML/default/viewer.htm#lrdictwhatsnew902...

Scroll down to the bottom to see how many new functions added to 9.2.

Haikuo

Super User
Posts: 9,681

how to use hash with duplicate key

You can make a HashTable's data field to be another HashTable.

I remember Dorfman who is named as Hash man has writen a paper for this case at SAS 9.1 a couple of years ago.

I have read it, but Sorry I can't find its link address any more.

Maybe you can search it at SAS Global Forum 2008 or 2009 paper list?

Ksharp

Ask a Question
Discussion stats
  • 4 replies
  • 260 views
  • 6 likes
  • 3 in conversation