DATA Step, Macro, Functions and more

Updating missing values question

Reply
Occasional Contributor
Posts: 9

Updating missing values question

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?

Super User
Posts: 5,085

Re: Updating missing values question

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.

Ask a Question
Discussion stats
  • 1 reply
  • 182 views
  • 0 likes
  • 2 in conversation