BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AlexeyS
Pyrite | Level 9

I want to keep all observation(after merging  tb1 and tbl2 ), but drop from it all observations that exist in tbl3.

the code is used is as follows:

proc sql;
create table tbl4 vas
select t1.*
from tbl1 t1
right join tbl2 t2 on t1.x1=t2.x1 and t1.x2=t2.x2 and t1.x3=t2.x3
where t1.x1 not in(select x1 from tbl3) and t1.x2 in(select x2 from tbl3) and t1.x3 in(select x3 from tbl3)
order by x1, x2, x3
;
quit;

 

What is wrong?

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Just an idea:

proc sql;
create table tbl4 as
  select t1.*
  from tbl1 t1
  right join tbl2 t2 on t1.x1=t2.x1 and t1.x2=t2.x2 and t1.x3=t2.x3
  left join tbl3 t3 on t1.x1=t3.x1 and t1.x2=t3.x2 and t1.x3=t3.x3
where t3.x1 is missing
order by t1.x1, t1.x2, t1.x3
;
quit;

View solution in original post

1 REPLY 1
Kurt_Bremser
Super User

Just an idea:

proc sql;
create table tbl4 as
  select t1.*
  from tbl1 t1
  right join tbl2 t2 on t1.x1=t2.x1 and t1.x2=t2.x2 and t1.x3=t2.x3
  left join tbl3 t3 on t1.x1=t3.x1 and t1.x2=t3.x2 and t1.x3=t3.x3
where t3.x1 is missing
order by t1.x1, t1.x2, t1.x3
;
quit;

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 lock in 2025 pricing—just $495!

Register now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 979 views
  • 0 likes
  • 2 in conversation