Applies to: | Hash object, Hash iterator object |
hash | indicates a hash object. The hash object provides a mechanism for quick data storage and retrieval. The hash object stores and retrieves data based on lookup keys. |
hiter | indicates a hash iterator object. The hash iterator object enables you to retrieve the hash object's data in forward or reverse key order. |
brown
for the key 620 and blue
for the
key 531 . If you use the default, green
would be stored for 620 and yellow
would be stored for 531.data table; input key data $; datalines; 531 yellow 620 green 531 blue 908 orange 620 brown 143 purple run; data _null_; length key 8 data $ 8; if (_n_ = 1) then do; declare hash myhash; myhash = _new_ hash (dataset: "table", duplicate: "r"); rc = myhash.definekey('key'); rc = myhash.definedata('data'); myhash.definedone(); end; rc = myhash.output(dataset:"otable"); run;
'ascending' | 'a' | Data is returned in ascending key-value order. Specifying
'ascending ' is the same as specifying
'yes '.
|
'descending' | 'd' | Data is returned in descending key-value order. |
'YES' | 'Y' | Data is returned in ascending key-value order. Specifying
'yes ' is the same as specifying 'ascending '.
|
'NO' | 'N' | Data is returned in some undefined order. |
'YES' | 'Y' | Multiple data items are allowed for each key. |
'NO' | 'N' | Only one data item is allowed for each key. |
dcl hash myhash(suminc: 'count');For more information, see Maintaining Key Summaries in SAS Language Reference: Concepts.
data kennel;
input name $1-10 kenno $14-15;
datalines;
Charlie 15
Tanner 07
Jake 04
Murphy 01
Pepe 09
Jacques 11
Princess Z 12
;
run;
data _null_;
if _N_ = 1 then do;
length kenno $2;
length name $10;
/* Declare the hash object */
declare hash h();
/* Instantiate and initialize the hash object */
h = _new_ hash(dataset:"work.kennel", ordered: 'yes');
/* Declare the hash iterator object */
declare hiter iter;
/* Instantiate the hash iterator object */
iter = _new_ hiter('h');
/* Define key and data variables */
h.defineKey('kenno');
h.defineData('name', 'kenno');
h.defineDone();
/* avoid uninitialized variable notes */
call missing(kenno, name);
end;
/* Find the first key in the ordered hash object and output to the log */
rc = iter.first();
do while (rc = 0);
put kenno ' ' name;
rc = iter.next();
end;
run;