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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.