/***************************************************************************************************************** SAS file name: tips_hash_object File location: _________________________________________________________________________________________________________________ Purpose: To present five tips to learn and understand the hash object in SAS Author: Peter Clemmensen Creation Date: 18/01/2019 This program supports the example page "5 Tips to Learn and Understand the Hash Object in SAS" on SASnrd.com *****************************************************************************************************************/ /* 1. Read the proper literature */ /* 2. The PDV and Host Variable Interaction */ data _null_; declare hash h(); h.defineKey('k'); h.defineData('d'); h.defineDone(); k=1;d=2; h.add(); /* PDV --> Hash Object */ k=2;d=4; h.add(); /* PDV --> Hash Object */ k=1; rc=h.find(); /* HAsh Object --> PDV */ put k= +2 d=; run; /* 3. The Hash Function */ data _null_; do i=1 to 50; string="Hash This!"; one=md5(string); two=sha256(string); put one hex32. / two hex32.; end; run; /* 4. An In-Memory Structure */ /* 5. The Ability to Grow and Shrink at Run Time */ data _null_; declare hash h(); h.defineKey('k'); h.defineData('d'); h.defineDone(); do k=1 to 10; d=k*2; h.add(); num=h.num_items; put num=; end; do k=10 to 1 by -1; h.remove(); num=h.num_items; put num=; end; run;