Previous Page | Next Page

Hash and Hash Iterator Object Language Elements

DEFINEKEY Method



Defines key variables for the hash object.
Applies to: Hash object

Syntax
Arguments
Details
See Also

Syntax

rc=object.DEFINEKEY('keyvarname-1'<..., 'keyvarname-n'>);
rc=object.DEFINEKEY(ALL: 'YES' | "YES");


Arguments

rc

specifies whether the method succeeded or failed.

A return code of zero indicates success; a non-zero value indicates failure. If you do not supply a return code variable for the method call and the method fails, then an appropriate error message is written to the log.

object

specifies the name of the hash object.

'keyvarname'

specifies the name of the key variable.

The key variable name can also be enclosed in double quotation marks.

ALL: 'YES' | "YES"

specifies all the data variables as keys when the data set is loaded in the object constructor.

If you use the dataset argument tag in the DECLARE statement or _NEW_ operator to automatically load a data set, then you can define all the key variables by using the ALL: 'YES' option.

Note:   If you use the shortcut notation for the ADD, CHECK, FIND, REMOVE, or REPLACE methods (for example, h.add(key:99, data:'apple', data:'orange')) and the ALL:'YES' option on the DEFINEKEY method, then you must specify the keys and data in the same order as they exist in the data set.  [cautionend]


Details

The hash object works by storing and retrieving data based on lookup keys. The keys and data are DATA step variables, which you use to initialize the hash object by using dot notation method calls. You define a key by passing the key variable name to the DEFINEKEY method. You define data by passing the data variable name to the DEFINEDATA method. When you have defined all key and data variables, you must call the DEFINEDONE method to complete initialization of the hash object. Keys and data consist of any number of character or numeric DATA step variables.

For detailed information about how to use the DEFINEKEY method, see Defining Keys and Data in SAS Language Reference: Concepts.

Note:   The hash object does not assign values to key variables (for example, h.find(key:'abc')), and the SAS compiler cannot detect the key and data variable assignments done by the hash object and the hash iterator. Therefore, if no assignment to a key or data variable appears in the program, SAS will issue a note stating that the variable is uninitialized. To avoid receiving these notes, you can perform one of the following actions:

  [cautionend]

See Also

Methods:

DEFINEDATA Method

DEFINEDONE Method

Operators:

_NEW_ Operator, Hash or Hash Iterator Object

Statements:

DECLARE Statement, Hash and Hash Iterator Objects

Defining Keys and Data in SAS Language Reference: Concepts.

Previous Page | Next Page | Top of Page