How do I lookup the hash table such that if there is a matched record, it will continue to lookup. If there is not matched record then i will just be blank?
/* Create test data */
data have_a;
input id name :$40.;
cards;
123456 Detroit
134567 Bordeaux
472831 Lille
;
data have_b;
input id name :&$40. parent_id parent_name :&$40.;
cards;
123456 Detroit 123450 Wayne County
123456 Detroit 319484 Bastille
123450 Wayne County 123400 Michigan
123400 Michigan 123000 USA
123000 USA 120000 North America
120000 North America 100000 Earth
134567 Bordeaux 134560 Gironde
134560 Gironde 134500 Nouvelle-Aquitaine
134500 Nouvelle-Aquitaine 134000 France
134000 France 130000 Europe
130000 Europe 100000 Earth
319484 Bastille 100001 Mars
319484 Bastille 100002 Venus
;
/* Perform look-ups */
data want;
if _n_=1 then do;
dcl hash h(dataset: 'have_b', multidata: 'y');
h.definekey('id');
h.definedata('parent_id', 'parent_name');
h.definedone();
if 0 then set have_b;
end;
array pid parent_id1-parent_id4;
array pn $40 parent_name1-parent_name4;
set have_a;
call missing(of parent:);
rc=h.find();
p_id=parent_id;
p_name=parent_name;
do i=1 to dim(pn) while(h.find(key: parent_id)=0);
pid[i]=parent_id;
pn[i]=parent_name;
end;
parent_id=p_id;
parent_name=p_name;
drop rc i p_:;
run;
I think this has been answered now in the original thread.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.