The code I tried is:
data mergeddata;
merge datasetA (in=in1) datasetB (in=in2);
by country;
run;
You need a join based on value and not a merge based on position. So switch to proc sql join, you will be fine.
data a;
input airline & $20. country :$15.;
cards;
Air Asia Vietnam
Vietjet Vietnam
;
data b;
input country $10. city & :$15.;
cards;
Vietnam Hanoi
Vietnam Ho Chi minh
;
proc sql;
create table want as
select a.*, city
from
a x1,b x2
where x1.country=x2.country;
quit;
Very good idea of using Hash
data a;
input airline & $20. country :$10.;
cards;
Air Asia Vietnam
Vietjet Vietnam
;
data b;
input country $10. city & :$15.;
cards;
Vietnam Hanoi
Vietnam Ho Chi minh
;
data want;
set a;
by country; /*sort not required but improves performance*/
if _n_=1 then do;
if 0 then set b;
declare hash H (dataset:'b',multidata:'y') ;
h.definekey ("country") ;
h.definedata ("city") ;
h.definedone () ;
end;
do rc=h.find() by 0 while(rc=0);
output;
rc=h.find_next();
end;
drop rc;
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: