BookmarkSubscribeRSS Feed
George_S
Fluorite | Level 6

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 1:(this works)

proc sql noprint;

create table C1 as

select a.*,b.a

from a

left join

b

on a.x=b.x

;

quit;

method 2:(this 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

4 REPLIES 4
Haikuo
Onyx | Level 15

First, are you running SAS 9.2 or above?

George_S
Fluorite | Level 6

SAS 9.1.3

Haikuo
Onyx | Level 15

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

Ksharp
Super User

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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1191 views
  • 6 likes
  • 3 in conversation