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:
ID | Amount |
123 | 45 |
48 | |
24 |
ID | Tax |
123 | 23 |
4 |
I want this output:
ID | Amount | Tax |
123 | 45 | 23 |
48 | . | |
24 | . | |
. | 4 |
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.
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.