Retrieves the summary value for the current data item of the current key and stores the value in a DATA step variable.
Applies to: | Hash object |
specifies whether the method succeeded or failed.
specifies the name of the hash object.
specifies a DATA step variable that stores the summary value for the current data item of the current key.
data dup;
length key data 8;
input key data;
cards;
1 10
2 11
1 15
3 20
2 16
2 9
3 100
5 5
1 5
4 6
5 99
;
data _null_;
length r i sum 8;
i = 0;
dcl hash h(dataset:'dup', multidata: 'y', suminc: 'i');
h.definekey('key');
h.definedata('key', 'data');
h.definedone();
call missing (key, data);
i = 1;
do key = 1 to 5;
rc = h.find();
if (rc = 0) then do;
h.has_next(result: r);
do while(r ne 0);
rc = h.find_next();
rc = h.find_prev();
rc = h.find_next();
h.has_next(result: r);
end;
end;
end;
i = 0;
do key = 1 to 5;
rc = h.find();
if (rc = 0) then do;
h.sum(sum: sum);
put key= data= sum=;
h.has_next(result: r);
do while(r ne 0);
rc = h.find_next();
h.sumdup(sum: sum);
put 'dup ' key= data= sum=;
h.has_next(result: r);
end;
end;
end;
run;
key=1 data=10 sum=2 dup key=1 data=15 sum=3 dup key=1 data=5 sum=2 key=2 data=11 sum=2 dup key=2 data=16 sum=3 dup key=2 data=9 sum=2 key=3 data=20 sum=2 dup key=3 data=100 sum=2 key=4 data=6 sum=1 key=5 data=5 sum=2 dup key=5 data=99 sum=2
key=1 data=10 sum=2 dup key=1 data=15 sum=3 dup key=1 data=5 sum=2
do key = 1 to 5;
loop,
the key summary for data item 10 is set to 1 on the initial FIND method
call. The first FIND_NEXT method call sets the key summary for data
item 15 to 1. The next FIND_PREV method call moves back to data item
10 and increments its key summary to 2. Finally, the last call to
the FIND_NEXT method increments the key summary for data item 15 to
2. The next iteration through the loop sets the key summary for data
item 5 to 1 and the key summary for data item 15 to 3. Finally, the
key summary for data item 5 is incremented to 2.