BookmarkSubscribeRSS Feed
erwint
Fluorite | Level 6

Hi!

 

I am working with two tables that have missing values for IDs. I am doing an outer join for the two tables. I want to make sure rows are only joined if the IDs are NOT null. I still would like these printed, just not joined. Can I do this in one SQL step?

Example: if I join these tables:

IDAmount
12345
 48
 24

 

IDTax
12323
 4

 

I want this output:

IDAmountTax
1234523
 48.
 24.
 .4
2 REPLIES 2
ballardw
Super User

Are any of the ID values other than missing repeated?

Do you expect the order of the Amount variable to remain the same in relation to the ID from the first set?

(Hint: provide some sort of name for the data sets so we can be sure which one anyone is discussing at a given point). Better: provide working data step code to provide example sets to write code against.

 

It is kind of hard to see what actual rules may be involved when only one matching ID is provided.

 

 

Tom
Super User Tom
Super User

So SAS equality tests will match missing values (of the same type of missing value).  So . will match . but not match .A or any actual number.

If you want exclude those then just add an additional condition.  Just test if one of the two values is missing should be enough.

select *
from A
  left join B
  on a.id = b.id and not missing(a.id) 
;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 448 views
  • 0 likes
  • 3 in conversation