/***************************************************************************************************************** SAS file name: hashofhash File location: _________________________________________________________________________________________________________________ Purpose: To demonstrate how hash objects can hold and point to other hash objects in SAS Author: Peter Clemmensen Creation Date: 20/01/2019 This program supports the example page "A SAS Hash Object Of Hash Objects (Hash Of Hash)" on SASnrd.com *****************************************************************************************************************/ /* Simple demonstration of the hash-of-hash method */ data _null_; if 0 then set sashelp.class sashelp.iris; declare hash HoH(ordered:'Y'); HoH.definekey ('ds'); HoH.definedata('h','ds'); HoH.definedone(); declare hiter HoHiter("HoH"); declare hash h; ds='sashelp.class'; h = _new_ hash(dataset:ds); h.definekey('name'); h.definedata(all:'Y'); h.definedone(); HoH.add(); ds='sashelp.iris'; h = _new_ hash(dataset:ds, multidata:'Y'); h.definekey('species'); h.definedata(all:'Y'); h.definedone(); HoH.add(); do while (HoHiter.next() = 0); numrows=h.num_items; put (ds numrows)(=); end; run; /* Expanding the Split Data Set By Group Approach to a not sorted data set */ data _null_; declare hash HoH(); HoH.definekey ('sex'); HoH.definedata('h','sex'); HoH.definedone(); declare hiter HoHiter("HoH"); declare hash h; do until (eof); set sashelp.class end=eof; if HoH.find() ne 0 then do; h=_new_ hash(dataset:'sashelp.class(obs=0)', multidata:'Y'); h.definekey('sex'); h.definedata(all:'Y'); h.definedone(); HoH.add(); end; h.add(); end; do while(HoHiter.next() = 0); h.output(dataset:cats('data_',sex)); end; run;