data have1;
var1=1;
do id=1,3,6;
output;
end;
run;
data have2;
var2=1;
do id=1 to 5;
output;
end;
run;
proc sql;
select t1.id, t1.var1, t2.var2
from have1 t1 left join have2 t2
on t1.id=t2.id
;
quit;
proc sql;
select t1.id, t1.var1, t2.var2
from have2 t2 right join have1 t1
on t1.id=t2.id
;
quit;
Keep all rows from the left side as opposed to keep all rows from the right side. But if you have a left join formulated and then switch to a right join and also switch your source tables accordingly then the result will be the same.
data have1;
var1=1;
do id=1,3,6;
output;
end;
run;
data have2;
var2=1;
do id=1 to 5;
output;
end;
run;
proc sql;
select t1.id, t1.var1, t2.var2
from have1 t1 left join have2 t2
on t1.id=t2.id
;
quit;
proc sql;
select t1.id, t1.var1, t2.var2
from have2 t2 right join have1 t1
on t1.id=t2.id
;
quit;
Register Today!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.