I would like to use obj.remove or obj.removedup at my own will and need based on a condition or just at a time when hiter points to the hash table. Soon as dcl hiter points to hash table and at the time of iteration backwards or forwards, it makes sense to lock the hash table as the hiter points to the hash table. Any option to override this behavior?
Thank you and happy long weekend
You can't delete items from a hash if a hiter object is linked to this hash.
You can mimic what a hiter can do for you by defining a hash with a constant key and then use the do_over() hash method to iterate over the whole hash.
data test(drop=_:);
if _n_=1 then
do;
/* map columns for hash */
if 0 then
do;
set sashelp.class(keep=name sex rename=(name=h_name sex=h_sex));
length _key $1;
retain _key '1';
end;
/* define the hash */
dcl hash h1(multidata:'y');
h1.defineKey('_key');
h1.defineData('h_name', 'h_sex');
h1.defineDone();
/* load data into the hash */
do _i=1 to nobs;
set sashelp.class(keep=name sex rename=(name=h_name sex=h_sex)) nobs=nobs point=_i;
h1.add();
end;
end;
set sashelp.class;
do while(h1.do_over() eq 0);
if name=h_name then
do;
h1.removedup();
leave;
end;
end;
run;
I don't understand. Could you provide a stepwise sequence to illustrate what you want?
You can't delete items from a hash if a hiter object is linked to this hash.
You can mimic what a hiter can do for you by defining a hash with a constant key and then use the do_over() hash method to iterate over the whole hash.
data test(drop=_:);
if _n_=1 then
do;
/* map columns for hash */
if 0 then
do;
set sashelp.class(keep=name sex rename=(name=h_name sex=h_sex));
length _key $1;
retain _key '1';
end;
/* define the hash */
dcl hash h1(multidata:'y');
h1.defineKey('_key');
h1.defineData('h_name', 'h_sex');
h1.defineDone();
/* load data into the hash */
do _i=1 to nobs;
set sashelp.class(keep=name sex rename=(name=h_name sex=h_sex)) nobs=nobs point=_i;
h1.add();
end;
end;
set sashelp.class;
do while(h1.do_over() eq 0);
if name=h_name then
do;
h1.removedup();
leave;
end;
end;
run;
Thank you sir @Patrick. Thats' exactly what i wanted to learn and know. Any "intuition" to why the lock can't be unlocked aka remove items from an original design structure point of view? opinion?
That piece will give me some smile to have comprehended after all.
I would appreciate your one more final response with a reference to hiter functionality in this case and sincerely close the thread.
Many thanks indeed.
I don't know how the hiter has been implemented and though can only guess that it establishes some sort of pointers to the underlying hash which would cause an error condition if removing the hash item to which a pointer points to. ....but that's really just me making up some explanation.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.