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.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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