Returns the first value in the underlying hash object.
Applies to: | Hash iterator object |
specifies whether the method succeeded or failed.
specifies the name of the hash iterator object.
ordered:
'yes'
or ordered: 'ascending'
argument
tag in the DECLARE statement or _NEW_ operator when you instantiate
the hash object, then the data item that is returned is the one with
the 'least' key (smallest numeric value or first alphabetic
character), because the data items are sorted in ascending key-value
order in the hash object. Repeated calls to the NEXT method will iteratively
traverse the hash object and return the data items in ascending key
order. Conversely, if you use the ordered: 'descending'
argument
tag in the DECLARE statement or _NEW_ operator when you instantiate
the hash object, then the data item that is returned is the one with
the 'highest' key (largest numeric value or last alphabetic
character), because the data items are sorted in descending key-value
order in the hash object. Repeated calls to the NEXT method will iteratively
traverse the hash object and return the data items in descending key
order.
data work.sales;
input prod $1-6 qty $9-14;
datalines;
banana 398487
apple 384223
orange 329559
;
data _null_;
/* Declare hash object and read SALES data set as ordered */
if _N_ = 1 then do;
length prod $10;
length qty $6;
declare hash h(dataset: 'work.sales', ordered: 'yes');
declare hiter iter('h');
/* Define key and data variables */
h.defineKey('qty');
h.defineData('prod');
h.defineDone();
/* avoid uninitialized variable notes */
call missing(qty, prod);
end;
/* Iterate through the hash object and output data values */
rc = iter.first();
do while (rc = 0);
put prod=;
rc = iter.next();
end;
run;
prod=orange prod=apple prod=banana