An Idea Exchange for SAS software and services

Comments
by Trusted Advisor
on ‎06-24-2014 12:21 AM

In what context does an HITER object not fulfill the requirement here?

by SAS Employee gergely_batho
on ‎06-24-2014 02:58 AM

Example:

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.

by Super User
on ‎06-24-2014 10:25 AM

I want a Hash Table's method to copy a Hash object into another Hash object.

by Trusted Advisor
on ‎06-24-2014 10:33 AM

It sounds to me like you are not aware of the HITER method SETCUR:

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a003123062.htm

data have;

format time datetime23.;

call streaminit(3131313131);

time='01JAN2012:0:0'dt;

do while (time le datetime());

time=intnx('hour' , time , 1+floor(1440*rand('uniform')) , 'b');

output;

end;

run;

data _null_;

if 0 then set have;

declare hash tm(dataset:'have' , ordered:'a');

declare hiter tmi('tm');

  tm.definekey('time');

tm.definedone();

set have (firstobs=10);

put time=;

tmi.setcur();

tmi.next();

put time=;

stop;

run;

by SAS Employee gergely_batho
on ‎06-24-2014 10:56 AM

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.)

by Trusted Advisor
on ‎06-26-2014 11:31 PM

What you could do in this situation is create a bisection in the established hash and then step forward to the next ordered key:

data have;

format time datetime23.;

call streaminit(3131313131);

time='01JAN2012:0:0'dt;

do while (time le datetime());

time=intnx('hour' , time , 1+floor(1440*rand('uniform')) , 'b');

output;

end;

run;

data _null_;

if 0 then set have;

declare hash tm(dataset:'have' , ordered:'a');

declare hiter tmi('tm');

  tm.definekey('time');

tm.definedone();

time='26JUN2013:10:30'dt; *a datetime not in hash;

put time=;

if tm.check() ne 0 then tm.add(); *bisect if not found;

_time=time; *store bisect value;

tmi.setcur();

tmi.next(); *for GT or tmi.prev() for LT;

tmi.remove(key:_time); *remove the bisect value;

put time=;

stop;

run;

by SAS Employee gergely_batho
on ‎06-27-2014 03:08 PM

What a trick! Thanks FriedEgg!

I'm going to experiment with this, and perhaps delete this "idea page".

by SAS Employee gergely_batho
on ‎09-11-2014 05:00 AM

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.

Thanks

by Frequent Contributor
on ‎09-11-2014 05:17 AM

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.

by SAS Employee gergely_batho
on ‎09-11-2014 05:25 AM

HITER does not have REMOVE method, only HASH has. Please create a "Discussion" when askin a question. Thx.

Idea Statuses
Top Liked Authors