/***************************************************************************************************************** SAS file name: hash_declare_instantiate File location: _________________________________________________________________________________________________________________ Purpose: To demonstrate the difference between declaring and instantiating a hash object in SAS Author: Peter Clemmensen Creation Date: 18/01/2019 This program supports the example page "Declaring and Instantiating the Hash Object in SAS" on SASnrd.com *****************************************************************************************************************/ /* Two different ways to declare and instantiate the hash object h */ data _null_; declare hash h; /* The hash object is declared PDV variable of type hash. Compile time only. */ h= _new_ hash(); /* A hash object instance is created of the hash object h. Run time only */ declare hash h(); /* This statement does exactly the same as the two statements above */ run; /* A hash object can only be declared once. The declaration operation without () is a compile time only statement */ data _null_; declare hash h1; declare hash h2; declare hash h1; /* A compile time error is produced here */ run; /* Remember that the SAS compiler does not care about conditional logic. Therefore, this does not produce an error */ data _null_; do i=1,2; declare hash h; end; run; /* A hash object can be declared only once. But we can create as many instances as the memory bounds allows */ data _null_; declare hash h; h=_new_ hash(); /* Instance 1 */ h=_new_ hash(); /* Instance 2 */ run;