/***************************************************************************************************************** SAS file name: hash_equals.sas File location: __________________________________________________________________________________________________________________ Purpose: To demonstrate the use of the Equals() Mehtod of the SAS hash object. Author: Peter Clemmensen Creation Date: 18Aug2019 This program supports the blog post "Are These Hash Objects Equal?" on SASnrd.com *****************************************************************************************************************/ /* Both hash objects are the same size */ data _null_; declare hash h1(hashexp:8); h1.definekey('k'); h1.definedone(); declare hash h2(hashexp:20); h2.definekey('k'); h2.definedone(); k=.; rc=h1.equals(hash: 'h2', result: r); put r=; run; /* Both hash objects have the same number of items */ data _null_; declare hash h1(); h1.definekey('k'); h1.definedata('d'); h1.definedone(); declare hash h2(); h2.definekey('k'); h2.definedata('d'); h2.definedone(); k=1; d=1; h1.add(); k=1; d=1; h2.add(); k=2; d=2; h2.add(); rc=h1.equals(hash: 'h2', result: r); put r=; run; /* Both hash objects have the same key and data structure */ data _null_; declare hash h1(); h1.definekey('k'); h1.definedata('d1', 'd2'); h1.definedone(); declare hash h2(); h2.definekey('k'); h2.definedata('d2', 'd1'); h2.definedone(); call missing(k, d1, d2); rc=h1.equals(hash: 'h2', result: r); put r=; run; /* In unordered iterations over two hash objects, they have the same key and data values for each entry */ data _null_; declare hash h1(ordered:'A'); h1.definekey('k'); h1.definedata('d'); h1.definedone(); declare hash h2(ordered:'D'); h2.definekey('k'); h2.definedata('d'); h2.definedone(); do k=1 to 10; d=k; h1.add(); end; do k=1 to 10; d=k; h2.add(); end; rc=h1.equals(hash: 'h2', result: r); put r=; run;