BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Depending on how you look at it - yes.

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;

Patrick_0-1702260997762.png

 

View solution in original post

3 REPLIES 3
Patrick
Opal | Level 21

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.

cosmid
Lapis Lazuli | Level 10
So they are essentially the same?
Patrick
Opal | Level 21

Depending on how you look at it - yes.

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;

Patrick_0-1702260997762.png

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!

Register now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1386 views
  • 2 likes
  • 2 in conversation