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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 712 views
  • 0 likes
  • 2 in conversation