Hash object keys are
not automatically stored as part of the output data set. The keys
must be defined as data items by using the DEFINEDATA method to be
included in the output data set.
If you use the
ordered: 'yes'
or
ordered: 'ascending'
argument tag in the DECLARE statement or _NEW_ operator when you
instantiate the hash object, then the data items are written to the
data set in ascending key-value order. If you use the
ordered: 'descending'
argument tag in the DECLARE
statement or _NEW_ operator when you instantiate the hash object,
then the data items are written to the data set in descending key-value
order. If you do not use the
ordered
argument tag, the order is undefined.
When specifying the
name of the output data set, you can use SAS data set options in the
DATASET argument tag. Data set options specify actions that apply
only to the SAS data set with which they appear. They let you perform
the following operations:
-
-
selecting a subset of observations
based on the observation number for processing
-
selecting observations using the
WHERE option
-
dropping or keeping variables from
a data set loaded into a hash object, or for an output data set that
is specified in an OUTPUT method call
-
specifying a password for a data
set.
The following example
uses the WHERE data set option to select specific data for the output
data set named OUT:
data x;
do i = 1 to 20;
output;
end;
run;
/* Using the WHERE option. */
data _null_;
length i 8;
dcl hash h();
h.definekey(all: 'y');
h.definedone();
h.output(dataset: 'out (where =( i < 8))');
run;
The following example uses the RENAME data set
option to rename the variable J to K for the output data set named
OUT:
data x;
do i = 1 to 20;
output;
end;
run;
/* Using the RENAME option. */
data _null_;
length i j 8;
dcl hash h();
h.definekey(all: 'y');
h.definedone();
h.output(dataset: 'out (rename =(j=k))');
run;
For a list of data set options, see
SAS Data Set Options: Reference.
Note: When you use the OUTPUT method
to create a data set, the hash object is not part of the output data
set. In the following example, the H2 hash object will be omitted
from the output data set.
data _null_;
length k 8;
length d $10;
declare hash h2();
declare hash h(ordered: 'y');
h.defineKey('k');
h.defineData('k', 'd', 'h2');
h.defineDone();
k = 99;
d = 'abc';
h.add();
k = 199;
d = 'def';
h.add();
h.output(dataset:'work.x');
run;