Add FIND_GE method for HASH object to find a key that is Greater or Equal then the specified value(s).
This would apply to sorted hash objects only. A twin method would be FIND_LE.
In what context does an HITER object not fulfill the requirement here?
I have a hash object, where the key is a time stamp, data is type of transaction
I want to get the first transaction since a specific time.
Walking from the start of the of the hash with hiter.next() is lengthy.
Currently I create a binned version of the time stamp, and use it as the key of the hash.
For example this creates “minute bins”: time_binned=time/’01:00’t
When searching, first I need to find the first non-empty bin (loop1), and then I have to loop through the time stamps in the bin (loop2).
If the internal representation of a sorted hash allows that, it would be more effective to use a find_ge() method.
I want a Hash Table's method to copy a Hash object into another Hash object.
It sounds to me like you are not aware of the HITER method SETCUR:
format time datetime23.;
do while (time le datetime());
time=intnx('hour' , time , 1+floor(1440*rand('uniform')) , 'b');
if 0 then set have;
declare hash tm(dataset:'have' , ordered:'a');
declare hiter tmi('tm');
set have (firstobs=10);
hiter.setcur() works only if you have an exact match in your hash table.
Add one second to time after the set statement (time=time+'00:01't; ), and it does not find anything.
Imagine you have transactions of customers in the hash table. For each customer you want to find the first deposit transaction since 01/6/2014:00:00:00.
Then maybe you want to skip to first withdrawal, and calculate the time between these two.
I would need the closest greater or equal time point in the hash table to the specified key.
But I could also use the feature to find nearest neighbors on a map. (Faster than I do it now.)
What you could do in this situation is create a bisection in the established hash and then step forward to the next ordered key:
time='26JUN2013:10:30'dt; *a datetime not in hash;
if tm.check() ne 0 then tm.add(); *bisect if not found;
_time=time; *store bisect value;
tmi.next(); *for GT or tmi.prev() for LT;
tmi.remove(key:_time); *remove the bisect value;
What a trick! Thanks FriedEgg!
I'm going to experiment with this, and perhaps delete this "idea page".
Hi All, I decided to keep this idea. I think it would be useful to use 1 method call instead of 5.
There are many other hash object method calls, that could be replaced by a couple of others, but they are useful, because they simplify coding (ref(), check(), etc.)
We have more and more time stamped data (calls, transactions, sensors, events). Finding "nearest neighbors" quickly is important in lot of applications.
I am getting the below error on this:
ERROR: Unknown method REMOVE for DATASTEP.HITER at line 483 column 1.
ERROR: DATA STEP Component Object failure. Aborted during the EXECUTION phase.
HITER does not have REMOVE method, only HASH has. Please create a "Discussion" when askin a question. Thx.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.