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 more
information about how to use the DEFINEKEY method, see Defining Keys and Data in SAS Language Reference: Concepts.
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.
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:
-
Set the NONOTES system option.
-
Provide an initial assignment statement
(typically to a missing value) for each key and data variable.
-
Use the CALL MISSING routine with
all the key and data variables as parameters. Here is an example:
length d $20;
length k $20;
if _N_ = 1 then do;
declare hash h();
rc = h.defineKey('k');
rc = h.defineData('d');
rc = h.defineDone();
call missing(k, d);
end;