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.
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;
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
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.
@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
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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.