To Astounding: I hate this mouthful of hash() approach as well, the mere intention of it is to construct a one-pass solution, which in the end is proven to be lower efficient by Art. So that doesn't work out.
To Art and Fareeza: Agreed with your comments on last record. It only takes minor tweak to the current Hash() code to fix that:
data have;
input (fn ln) (:$20.) grade;
cards;
Ross Smith 11
Jayden Woo 10
Ross Smith 7
Jayden Woo 8
Ross Smith 6
;
/*theorically one-pass(I/O) approach*/
data want;
declare hash full(ordered:'y');
full.definekey('_n_');
full.definedata('fn','ln','grade');
full.definedone();
declare hiter hif('full');
declare hash hoh();
hoh.definekey('fn','ln');
hoh.definedata('fn','ln','lst','hil');
hoh.definedone();
declare hash lst;
declare hiter hil;
do _n_=1 by 1 until (done);
set have end=done;
l_grade=grade;
if hoh.find() ne 0 then do;
lst=_new_ hash (ordered:'d');
lst.definekey('_n_');
lst.definedata('fn','ln','l_grade');
lst.definedone();
hil=_new_ hiter ('lst');
hoh.replace();
end;
lst.replace();
full.replace();
end;
do _rc=hif.next() by 0 while (_rc=0);
hoh.find();
hil.first();
output;
_rc=hif.next();
end;
stop;
drop _rc;
run;
Haikuo
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.