/* Richard A. DeVenezia * www.devenezia.com * 25May2004 * * Similar to material originally posted to SAS-L on May 24, 2004 * "Hash of hashes and dynamic output" */ * data with several groups; data x0; do group = 'a','c','d','e'; do row = 1 to 100; satellite_1 + 1; satellite_2 = 0; satellite_A = 'foo bar'; output; end; end; run; * disorder for good measure; proc sql; create table x as select * from x0 order by ranuni(1); quit; * split one data into several data named according to group var; data _null_; declare hash h0 (); h0.defineKey ('group'); h0.defineData ('group', 'h'); * hash of hashes, data element h is a hash object; h0.defineDone (); declare hash h; do until (endOfDataset); set x end = endOfDataset; if 0 ne h0.find() then do; * create a hash for the group; h = _new_ hash (ordered:'a'); h.defineKey ('row'); h.defineData ('row', 'satellite_1' , 'satellite_2' , 'satellite_A'); h.defineDone (); h0.replace(); end; * add data to the groups hash; h.replace (); end; declare hiter hi ('h0'); * create one table for each group; do rc = hi.first() by 0 while (rc = 0); * each data part of h0 contains a reference to a hash; * first() and next() will place that reference in h * h is then used to output the data of the group into a table; h.output (dataset:'group_'||group); rc = hi.next(); end; run;