| Date: | Tue, 25 May 2004 12:13:35 -0400 |
| Reply-To: | "Richard A. DeVenezia" <radevenz@IX.NETCOM.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | "Richard A. DeVenezia" <radevenz@IX.NETCOM.COM> |
| Subject: | [v9.1] Hash of hashes and dynamic output |
|---|
In the "Seperate data set" thread it was stated "( I won't get into
<hash>.output(dataset:... "
Well here it is gotten into...
Suppose you want to split a table containing several groups of rows into
several tables containing one group each.
* data with several groups;
data x;
do group = 'a','c','d','e';
do row = 1 to 100;
v + 1;
output;
end;
end;
run;
* disorder for good measure;
proc sql;
create table x as select * from x order by ranuni(1);
quit;
* split one data into several data;
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', 'v');
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;
--
Richard A. DeVenezia
http://www.devenezia.com/downloads/sas/samples
|