/***************************************************************************************************************** SAS file name: hash_point.sas File location: __________________________________________________________________________________________________________________ Purpose: To demonstrate how to use record pointers to reduce hash object memory. Author: Peter Clemmensen Creation Date: 16/07/2020 This program supports the blog post "Using the SAS Hash Object and Point= Option" on SASnrd.com *****************************************************************************************************************/ /* Example data */ data master (keep = k) lookup; do _N_ = 1 to 1e6; k = uuidgen(); array d $ 200 d1-d10; do over d; d = uuidgen(); end; if rand('uniform') < .5 then output lookup; output master; end; run; proc contents data=lookup;run; /* Naive Hashing - Most systems crash due to memory failure.*/ data hash (drop=rc); if 0 then set lookup; array d $ 200 d1-d10; if _N_ = 1 then do; before=input(getoption('xmrlmem'),20.); declare hash h (dataset : "lookup"); h.definekey ("k"); do over d; h.definedata (vname(d)); end; h.definedone (); after=input(getoption('xmrlmem'),20.); hashsize=before-after; put "Hash Object Takes Up:" hashsize sizekmg10.2; end; set master; call missing (of d:); rc = h.find(); run; /* Hash + Point= Option */ data hashpoint; declare hash h (); h.definekey ("k"); h.definedata ("p"); h.definedone (); before=input(getoption('xmrlmem'),20.); do p = 1 by 1 until (lr1); set lookup end=lr1; h.add(); end; after=input(getoption('xmrlmem'),20.); hashsize=before-after; put "Hash Object Takes Up:" hashsize sizekmg10.2; do until (lr2); set master end=lr2; call missing (of d:); if h.find() = 0 then set lookup point=p; output; end; run; /* Verify that the two approaches yield the same result */ proc compare base=hash comp=hashpoint; run;