Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TableA without Matching TableB 1

Status
Not open for further replies.

DonaZ

Technical User
Oct 10, 2007
41
US
I have two tables--TableA and TableB.
I want the records from TableA that does not match TableB.
Below is my query. What am I doing wrong?

proc sql;
create table NewTable/*name*/ as
select distinct a.id,a.*
from /*table name*/TableA a left join TableB b
on a.id=b.id
where a.id <> b.id
;
quit;


Thank you for your time.
Donaz
 
Try changing your where statement to "where b.id is null". That might do it.
Alternatively you can try:-
Code:
proc sql;
  create table NewTable as
  select A.*
  from TableA  A
  where A.id not in(select ID
                    from TableB)
   ;
quit;
This will work, but is not necessarily very efficient. If your tables are very large (100k+) this will take some time to process. Might be worth trying both methods to see which works best.

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Chris,
Thank you again for your time.
Both options worked. When I have time, I will test it with larger tables.

Donaz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top