Hi guys,
I am trying hard to figure out how this works and I can't seem to manage it. Why do I get any output on the phone and email of Henry using the code below? It seems to me that the hash object doesn't seem to look up the values based on the name and age as specified in the key. Am I doing something wrong?
Thank you
data H_one;
length
name $10
age 8
address $20
;
input name $ age address $;
datalines;
John 8 Street_123
John 15 Drive_456
Henry 23 Road_789
run;
data H_two;
length
name $10
age 8
phone $10
email $20
;
input name $ age phone $ email $;
datalines;
John 8 1234 abc@abc
John 15 5678 def@def
ABC 25 91011 ghi@ghi
DEF 29 23232 jkl@jkl
run;
data H_three;
set one;
length
phone $10
email $20
;
if _N_=1 then do;
declare hash h(dataset:"work.two");
h.definekey("name","age");
h.definedata("phone", "email");
h.definedone();
end;
rc = h.find();
run;
You created datasets: H_one, H_two
but in your 3rd step your reference to work.ONE, work.TWO
change last step to:
data H_three; set H_one; length
phone $10
email $20
;
if _N_=1 then do;
declare hash h(dataset:"work.H_two");
h.definekey("name","age");
h.definedata("phone", "email");
h.definedone();
end;
rc = h.find();
run;
You created datasets: H_one, H_two
but in your 3rd step your reference to work.ONE, work.TWO
change last step to:
data H_three; set H_one; length
phone $10
email $20
;
if _N_=1 then do;
declare hash h(dataset:"work.H_two");
h.definekey("name","age");
h.definedata("phone", "email");
h.definedone();
end;
rc = h.find();
run;
Because phone and email have been retained . Call missing them before h.find(). if _N_=1 then do; declare hash h(dataset:"work.two"); h.definekey("name","age"); h.definedata("phone", "email"); h.definedone(); end; call missing(phone,email); rc = h.find();
Can't believe I did such a stupid mistake, thanks a lot for your support 🙂
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.