BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mkeintz
PROC Star

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.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Astounding
PROC Star

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.

mkeintz
PROC Star

Thanks for the reminder.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
ArtC
Rhodochrosite | Level 12

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

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!

What is Bayesian Analysis?

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.

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
  • 18 replies
  • 1362 views
  • 4 likes
  • 7 in conversation