Hey, I have a rather simple problem which does have many ways to overcome but in the context I'm working at it would be more than appreciated to be able to solve the issue with the "reset" method explained below: * Create testdata ;
data testdata;
do value = 1 to 6;
if value <= 3
then keyval = "key1";
else keyval = "key2";
output;
end;
run;
* Create index for testdata ;
proc datasets lib = work;
modify testdata;
index create keyval;
run;
* Result as expected: key1 is found twice and key2 once ;
data result_valid;
if 0 then set testdata;
do keyval = "key1", "key2", "key1";
do until(_iorc_ ne 0);
set testdata key = keyval;
iorc = _iorc_; /* Just for test purposes, remove if condition below to test it */
if _iorc_ = 0 then output;
end;
end;
stop;
run;
* But subsequent identical keyval -values does not provide expected result ;
* - In the background key "pointer" is not reset after the previous search ;
* -- Question is: Is there any way to reset it? ;
data result_invalid;
if 0 then set testdata;
do keyval = "key1", "key1", "key2";
do until(_iorc_ ne 0);
set testdata key = keyval;
iorc = _iorc_; /* Just for test purposes, remove if condition below to test it */
if _iorc_ = 0 then output;
end;
end;
stop;
run;
* Similar processing happens with simple data step: Reult_simple contains only one row ;
data result_simple;
do i = 1 to 3;
set sashelp.cars(obs = 1);
output;
end;
run;
* But with point processing it works ;
data result_point;
do i = 1, 1, 1;
set sashelp.cars point = i;
output;
end;
stop;
run; Workaround tried: * Attempt to reset "pointer" by calling a dummy key if subsequent keys are found ;
* -> No success ;
data result_invalid;
if 0 then set testdata;
do keyval = "key1", "key1", "key2";
if prev_key = keyval then do;
* Try to reset pointer for "key1" ;
_tmp_key = keyval;
keyval = "dumm";
set testdata key = keyval;
prev_key = _tmp_key;
end;
else prev_key = keyval;
do until(_iorc_ ne 0);
set testdata key = keyval;
iorc = _iorc_; /* Just for test purposes, remove if condition below to test it */
if _iorc_ = 0 then output;
end;
end;
stop;
run;
... View more