/***************************************************************************************************************** SAS file name: hash_object_fail.sas File location: __________________________________________________________________________________________________________________ Purpose: To list the most common reasons why the SAS hash object yields an error. Author: Peter Clemmensen Creation Date: 05Sep2019 This program supports the blog post "5 Reasons Why Your Hash Object Fails" on SASnrd.com *****************************************************************************************************************/ /* Missing Parameter Type Matching */ data _null_; declare hash h(); h.definekey('k'); h.definedata('d'); h.definedone(); run; /* The Hash Object Exceeds Memory */ data _null_; declare hash h(); h.definekey('k'); h.definedata('d'); h.definedone(memrc:'y'); k=.; length d $ 1000; do k=1 to 1e7; rc=h.add(); end; run; /* Failed Unassigned Method Call */ data _null_; declare hash h(); h.definekey('k'); h.definedata('d'); h.definedone(); k=.; d=.; h.find(key: 1); run; /* Duplicate keys without the multidata:'Y' argument tag */ data _null_; declare hash h(); h.definekey('k'); h.definedata('d'); h.definedone(); k=.; d=.; h.add(key: 1, data: 1); h.add(key: 1, data: 1); run; /* Remember the parenthesis */ data _null_; declare hash h(); h.definekey('k'); h.definedata('d'); h.definedone(); k=1; d=1; rc=h.add(key: 1, data: 1); rc=h.find; run;