06-19-2012 02:45 PM
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?
06-19-2012 03:35 PM
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:
update master updates;
Nonmissing values in master get replaced if nonmissing values also appear in updates. But this program gives you exactly what you want:
update updates master;