BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ybz12003
Rhodochrosite | Level 12

Hello, 

 

I have two datasets, A and B. A contains 56 codes, and B has 53 codes. Dataset B is coming from A. I would like to find the 3 unmatching codes that B doesn't have. My code is listed below. But the result I got was still 56 obs, not the 3 unmatching codes. Please help me find where I went wrong.

 

proc sql; 
   create table Code_unMatch as
	   select DISTINCT a.code      
	   from Master_Code as a
   left join code_check as b    
	   on a.code=b.OBR_Code
	   order by a.code;
quit;
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

See if this helps:

Except is designed to get unmatched from one set in another.

proc sql; 
   create table Code_unMatch as
	   select DISTINCT code      
	   from Master_Code
      except 
	   select distinct obr_code as code
	          from code_check
      ;
quit;

If you do a LEFT(or Right) join without a WHERE clause to reduce the results you always get all the records from the Left(or right) source.

 

The join approach would look like:

proc sql; 
   create table Code_unMatch as
	   select DISTINCT a.code      
	   from Master_Code as a
   left join code_check as b    
	   on a.code=b.OBR_Code
      where not missing(b.obr_code)
	   order by a.code
   ;
quit;

View solution in original post

2 REPLIES 2
ballardw
Super User

See if this helps:

Except is designed to get unmatched from one set in another.

proc sql; 
   create table Code_unMatch as
	   select DISTINCT code      
	   from Master_Code
      except 
	   select distinct obr_code as code
	          from code_check
      ;
quit;

If you do a LEFT(or Right) join without a WHERE clause to reduce the results you always get all the records from the Left(or right) source.

 

The join approach would look like:

proc sql; 
   create table Code_unMatch as
	   select DISTINCT a.code      
	   from Master_Code as a
   left join code_check as b    
	   on a.code=b.OBR_Code
      where not missing(b.obr_code)
	   order by a.code
   ;
quit;
PaigeMiller
Diamond | Level 26

Try this:

 

proc sql; 
   create table Code_unMatch as
	   select DISTINCT a.code,b.OBR_Code      
	   from Master_Code as a
   full join code_check as b    
	   on a.code=b.OBR_Code
	   order by a.code;
quit;

You should find the unmatching text this way.

--
Paige Miller

sas-innovate-white.png

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.

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2 replies
  • 575 views
  • 2 likes
  • 3 in conversation