Use the UPDATE statement, which only takes values from the right hand data set (HAVE below) if they are not missing. It writes out only one record per id (and expects only one incoming record per id in the MASTER data set). It treats the right hand data set (HAVE) as a series of "transactions" to apply to master.
In this example, even though there are 2 steps, there is only one pass through of the original dataset HAVE. That's because MASTER is a data set view, and won't be activated until it is used in a subsequent step. It's sort of a data "pipe".
The only assumption here is that HAVE is sorted by ID.
data master / view=master;
set have;
by id;
if first.id;
run;
data want;
update master have;
by id;
run;
I'd add that the benefit of this technique is that you don't need to know the names of any variables except the BY variable.
Or the lazy man's version of UPDATE:
data want;
update have (obs=0) have;
by id;
run;
It does assume that the data are sorted.
Thanks for the reminder.
For more information on the UPDATE approach (with some alternate examples) shown by @Astounding take a look at:
https://communities.sas.com/thread/32502 and http://www.sascommunity.org/wiki/Tips:Using_UPDATE_to_Collapse_a_Data_Set
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.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.