BookmarkSubscribeRSS Feed
Alphanumeric
Obsidian | Level 7

I have two datasets that are structured the same but some values in one are missing whereas they may or may not be missing in the other and vice versa. I was looking for a way to combine the two datasets and only having the missing variables be overwritten with existing values of the other dataset. Is this possible to do? As I read it, the update statement will overwrite the values of one table with values from the other table including missings, but also all the other values it finds. Is there a command to only overwrite if values are missing?

1 REPLY 1
Astounding
PROC Star

Think about it ... you already have the tools you need.

Let's work with these assumptions:

master = data set with the good information, but a few missing values

updates = data set with additional information that should replace only the missing values in master

Both data sets are sorted by ID, and contain at most one observation per ID.  (We can work around that if it's not the case.)

To get what you are looking for, you have noted that this will fail:

data final;

update master updates;

by id;

run;

Nonmissing values in master get replaced if nonmissing values also appear in updates.  But this program gives you exactly what you want:

data final;

update updates master;

by id;

run;

Good luck.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1 reply
  • 1113 views
  • 0 likes
  • 2 in conversation