BookmarkSubscribeRSS Feed
jpm2478
Calcite | Level 5

Hi,

 

I'm using Hash Object and I'm trying to get the Output to overwrite the initial dataset (Y). I'm using  if last then h.output(dataset:'work.y');

where work.Y is an initial dataset.

 

When I run this code the Output is not shown in Work.Y but when I use a newdataset name like  if last then h.output(dataset:'AA'); the output is shown in new dataset AA.

 

How do I get Hash Output to be shown on the Initial Dataset.

5 REPLIES 5
SuryaKiran
Meteorite | Level 14

Are you trying to update a dataset using the values from other dataset? 

 

Try this if so:

data have;  
  if _n_=1 then do;
    declare hash ud(dataset:'update');
    ud.defineKey('id');
    ud.defineData('val1', 'val2');
    ud.defineDone();
  end;
  modify have;
  rcUpdate = ud.find();
  if rcUpdate=0 then replace;
run;
Thanks,
Suryakiran
novinosrin
Tourmaline | Level 20

Hi @jpm2478 If your question relates to the thread https://communities.sas.com/t5/SAS-Procedures/Compare-two-datasets-using-Hash-and-update-values/m-p/...

 

You can try options 1. modify statement, 2. @ballardw 's non hash solution among others etc

 

Of course if you are comfortable with hashes, by all means do explore. Hash understanding is tricky for the reason understanding 

 

PDV::Memory table   key value pair matches can be confusing and pulling from Memory table ::  PDV along with it can be daunting. But  totally up to you

mkeintz
PROC Star

Are you trying to use hash output method to overwrite a data set that your are reading from in the same data step?   I don't believe you can do that.

--------------------------
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

--------------------------
novinosrin
Tourmaline | Level 20

@mkeintz Sir, I believe that's exactly OP's req. I wish I was brilliant using modify statement and automatic vars associated with it like you demonstrated in one your posts which I regret I failed to add to my notes. If i had it, I would have plagiarized it and demonstrated here3

mkeintz
PROC Star

@novinosrin

 

You may be referring to Update and replace data in a table, but that problem was only to decide whether to replace the last record in the master, or to append the record.  I think this problem has to do with multiple transaction/update records.  In which case @SuryaKiran's solution seems apt - as long as the UPDATE dataset has only one record per id.

 

edited revision:  ... and also assuming that there are no new id's in UPDATE.

 

 

--------------------------
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

--------------------------

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
  • 5 replies
  • 871 views
  • 0 likes
  • 4 in conversation