/***************************************************************************************************************** SAS file name: hash_iterator.sas File location: __________________________________________________________________________________________________________________ Purpose: To introduce and demonstrate how to use the Hash Iterator in SAS Author: Peter Clemmensen Creation Date: 23/08/2019 This program supports the blog post "An Introcution to The Hash Iterator in SAS" on SASnrd.com *****************************************************************************************************************/ /* Declating a has iterator object and link it to a hash object */ data _null_; key=.; data=.; declare hash h(); h.definekey('key'); h.definedata('data'); h.definedone(); declare hiter hi('h'); /* Equivalent to declare hiter hi; hi = _NEW_ hiter('h'); */ run; /* Iterate through an entire hash object */ data _null_; declare hash h(ordered:'Y'); h.definekey('key'); h.definedata('key', 'data'); h.definedone(); declare hiter hi('h'); do key=1 to 4; data=key*2; h.add(); end; do rc=hi.first() by 0 while (rc=0); put key= data=; rc=hi.next(); end; /* Backwards */ do rc=hi.last() by 0 while (rc=0); put key= data=; rc=hi.prev(); end; run;