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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 128 views
  • 0 likes
  • 3 in conversation