Creates an instance of a hash or hash iterator object.
Applies to: | Hash object, Hash iterator object |
specifies the object reference name for the hash or hash iterator object.
specifies the component object. It can be one of the following:
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. |
See | Using DATA Step Component Objects in SAS Language Reference: Concepts and Using the Hash Iterator Object in SAS Language Reference: Concepts |
specifies the information that is used to create an instance of the hash object.
names a SAS data set to load into the hash object.
dcl hash h; h = _new_ hash (dataset: 'x (where = (i > 10))');
Note | If the data set contains duplicate keys, the default is to keep the first instance in the hash object; subsequent instances are ignored. To store the last instance in the hash object or to write an error message in the SAS log if there is a duplicate key, use the DUPLICATE argument tag. |
determines whether to ignore duplicate keys when loading a data set into the hash object. The default is to store the first key and ignore all subsequent duplicates. Option can be one of the following values:
stores the last duplicate key record.
reports an error to the log if a duplicate key is found.
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;
is the hash object's internal table size, where the size of the hash table is 2n.
Default | 8, which equates to a hash table size of 28 or 256 |
specifies the name of a variable that tracks the key summary for all keys. A key summary is a count of how many times a key has been referenced on a FIND method call.
Note | The key summary is in the output data set. |
specifies whether or how the data is returned in key-value order if you use the hash object with a hash iterator object or if you use the hash object OUTPUT method.
'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. |
Default | NO |
specifies whether multiple data items are allowed for each key.
option
can
be one of the following values:
'YES' | 'Y' | Multiple data items are allowed for each key. |
'NO' | 'N' | Only one data item is allowed for each key. |
Default | NO |
See | Non-Unique Key and Data Pairs in SAS Language Reference: Concepts |
maintains a summary count of hash object keys. The SUMINC argument tag is given a DATA step variable, which holds the sum increment. The sum increment is how much to add to the key summary for each reference to the key. For example, a key summary changes using the current value of the DATA step variable.
dcl hash myhash(suminc: 'count');
See | Initializing Hash Object Data Using a Constructor in SAS Language Reference: Concepts and Declaring and Instantiating a Hash Object in SAS Language Reference: Concepts |
declare hash h(); h = _new_ hash( );
declare hash h(); h = _new_ hash(datset: "work.kennel");
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;
NOTE: There were 7 observations read from the data set WORK.KENNEL. 01 Murphy 04 Jake 07 Tanner 09 Pepe 11 Jacques 12 Princess Z 15 Charlie