/* * Richard A. DeVenezia * June 19, 2004 * A demonstration of multi-level hash (mlh) * * Note: demonstration only. * Almost anything done with a MLH can (and should) be done * by using Proc SORT, DATA Step with BY statements and/or * PROC Steps with BY and CLASS statements. * * I have yet to find a reasonable sample problem that * demonstrates MLH as the principally simplest solution * technique. If one is found it will probably involve * atypical path following algorithms or recursive searches. * MLH is a technique waiting for a problem. * */ dm 'clear log' log; %include "\\extreme\macros\multi-level-hash.sas"; data level1; input factory $; cards; Dryville Wetville Remsen Footown Barsoom run; data level2; input line $; cards; Sponge Sprocket Rocket Shocker Steamer Vatbeer Vanilla Generic Zooker run; data level3; input operator $; cards; Anasta Bill Ben Chester Dobby Eugene Francis Gulliver Handren Illian Jacoby Klein Ludicrous Malcolm Nembry run; data level4; input attitude $; cards; good bad ugly flat sharp plain exhub down ; data level5; input season $; cards; summer winter spring fall run; data study; retain seed 1; do i = 1 to 5; *3000; p1 = 1 + n1*ranuni(seed); p2 = 1 + n2*ranuni(seed); p3 = 1 + n3*ranuni(seed); p4 = 1 + n4*ranuni(seed); p5 = 1 + n5*ranuni(seed); set level1 nobs=n1 point=p1; set level2 nobs=n2 point=p2; set level3 nobs=n3 point=p3; set level4 nobs=n4 point=p4; set level5 nobs=n5 point=p5; n = 1 + 4 * ranuni(seed); n=2; do j = 1 to n; zackford = int (1000 * ranuni(seed)); flurm = int (1000 * ranuni(seed)); wrench = int (1000 * ranuni(seed)); bolly = int (1000 * ranuni(seed)); woggle = int (1000 * ranuni(seed)); output; end; end; STOP; drop i j n seed; format _numeric_ 4.; run; option mprint; data _null_; %* prep PDV; if 0 then set study; %MLH_Start ( mlh , keys=factory : line : operator : season : attitude , data=bolly woggle zackford , debug=no) do until (endOfData); set study end=endOfData; %MLH_Set (mlh, debug=no ) end; /* %MLH_Dump (mlh) %MLH_Foreach (mlh, link=section8) */ factory='Barsoom'; line='Steamer'; operator='Nembry'; season='summer'; attitude='plain'; put / 'Data of ' factory= line= operator= season= attitude= / 8*'-'; %MLH_Get (mlh) declare hiter h; h = _new_ hiter ('mlh_node'); do rc = h.first() by 0 while (rc=0); put bolly= woggle= zackford=; rc = h.next(); end; h.delete(); put / 'Factories of Dataset:Study' / 8*'-'; %MLH_Get (mlh,0) h = _new_ hiter ('mlh_node'); do rc = h.first() by 0 while (rc=0); put factory=; rc = h.next(); end; h.delete(); put / 'Lines of Factory=Barsoom' / 8*'-'; factory='Barsoom'; %MLH_Get (mlh,1) h = _new_ hiter ('mlh_node'); do rc = h.first() by 0 while (rc=0); put line=; rc = h.next(); end; h.delete(); %MLH_Finish (mlh) stop; section8: put factory= line= operator= season= attitude= bolly= woggle= zackford=; return; run;