Any custom option or possibility to unlock a hash table when a hiter object points to it?

Accepted Solution Solved
Reply
PROC Star
Posts: 1,833
Accepted Solution

Any custom option or possibility to unlock a hash table when a hiter object points to it?

[ Edited ]

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


Accepted Solutions
Solution
‎05-27-2018 09:28 AM
Respected Advisor
Posts: 4,736

Re: Any custom option or possibility to unlock a hash table when a hiter object points to it?

Posted in reply to novinosrin

@novinosrin

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;

View solution in original post


All Replies
Trusted Advisor
Posts: 1,345

Re: Any custom option or possibility to unlock a hash table when a hiter object points to it?

Posted in reply to novinosrin

I don't understand.  Could you provide a stepwise sequence to illustrate what you want?

 

Solution
‎05-27-2018 09:28 AM
Respected Advisor
Posts: 4,736

Re: Any custom option or possibility to unlock a hash table when a hiter object points to it?

Posted in reply to novinosrin

@novinosrin

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;
PROC Star
Posts: 1,833

Re: Any custom option or possibility to unlock a hash table when a hiter object points to it?

[ Edited ]

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. 

Respected Advisor
Posts: 4,736

Re: Any custom option or possibility to unlock a hash table when a hiter object points to it?

[ Edited ]
Posted in reply to novinosrin

@novinosrin

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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 225 views
  • 2 likes
  • 3 in conversation