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
First, are you running SAS 9.2 or above?
SAS 9.1.3
That explains it. SAS hash does not support duplicate key until 9.2
Scroll down to the bottom to see how many new functions added to 9.2.
Haikuo
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
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.
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.