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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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