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

 

CFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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
  • 2404 views
  • 2 likes
  • 2 in conversation