/***************************************************************************************************************** SAS file name: hash_many_var.sas File location: __________________________________________________________________________________________________________________ Purpose: To demonstrate how to read many variables into a SAS hash object. Author: Peter Clemmensen Creation Date: 13/06/2020 This program supports the blog post "Read Many Variables Into the SAS Hash Object" on SASnrd.com *****************************************************************************************************************/ /* Example Data */ data have; do _N_ = 1 to 10; k = ceil(rand('uniform')*100); array d $ 8 d1-d100; do over d; d = uuidgen(); end; output; end; run; /* Using SAS Metadata */ proc sql noprint; select quote(strip(name)) into : d separated by ',' from dictionary.columns where libname = "WORK" and memname = "HAVE" and char(name, 1) = "d"; run; %put &d.; data _null_; if 0 then set have; declare hash h (dataset : "have"); h.definekey ("k"); h.definedata (&d.); h.definedone (); h.output (dataset : "hashcontent"); run; /* Using an implicit array */ data _null_; if 0 then set have; declare hash h (dataset : "have"); h.definekey ("k"); h.definedata ("d1"); h.definedata ("d2"); h.definedata ("d3"); h.definedone (); h.output (dataset : "hashcontent"); run; data _null_; if 0 then set have; array d d:; declare hash h (dataset : "have"); h.definekey ("k"); do over d; h.definedata (vname(d)); end; h.definedone (); h.output (dataset : "hashcontent"); run; /* Read all character variables into the data portion */ data _null_; if 0 then set have; array d _character_ /* _numeric */; declare hash h (dataset : "have"); h.definekey ("k"); do over d; h.definedata (vname(d)); end; h.definedone (); h.output (dataset : "hashcontent"); run;