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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.