Hi.
Maybe someone can share tips or suggestions how to complete following use case:
So far I have been able to use pattern window to implement 30 minute rule but ran out of ideas.
I also tried to use functional window to calculate difference between two timestamp fields that pattern window outputs but regular calculations don't work: $ending_timestamp-$starting_timestamp; integer($ending_timestamp)- integer($starting_timestamp) or number($ending_timestamp)-number($starting_timestamp).
Thank you.
Rain
Another approach is to code the lower bound of the time frame in the second event of interest. This example looks for e2 to occur between 10 and 30 minutes after e1. (10 min is equivalent to 0.00694444 days).
<events>
<event source="Src" name="e1"><![CDATA[direction=='OUT' and var_number==number
and var_timestamp==timestamp]]></event>
<event source="Src" name="e2"><![CDATA[direction=="IN" and var_number==number
and var_timestamp<timestamp - 0.00694444]]></event>
</events>
<logic>fby{1800 seconds}(e1, e2)</logic>
As a follow up , the difference (in seconds) between two timestamp fields can be calculated in the functional window with the following:
<function name="difference"><![CDATA[product(diff($timestamp2, $timestamp1), 0.000001)]]></function>
Here, “difference” is type double.
I apologize that I am not able to prototype this at the moment but what about something like this?
<pattern>
<events>
<event name=‘anyEvent'>(1==1) </event>
<event name='e1'>(Whatever the condition) </event>
<event name='e2'>(Whatever the condition)></event>
</events>
<logic>fby{10 minutes}(anyEvent,fby{30 minutes}(e1,e2))</logic>
...
Hi Stephen and thank you for quick reply.
I tried your suggestion but no success yet. Pattern window looks like this:
<patterns>
<pattern name="mypattern">
<events>
<event name="e0" source="source_window"><![CDATA[(1==1)]]>
</event>
<event name="ev1" source="source_window"><![CDATA[var_number==number and direction=='OUT']]> </event>
<event name="ev2" source="source_window"><![CDATA[var_number==number and direction=='IN']]> </event>
</events>
<logic><![CDATA[fby{600 seconds}(e0, fby{7200 seconds}(e1, e2))]]></logic>
<output>
....
</output>
<timefields>
<timefield source="source_window" field="date"/>
</timefields>
</pattern>
</patterns>
This pattern, having one time boundary, works just fine:
<events>
<event name="ev1" source="source_window"><![CDATA[var_number==number and direction=='OUT']]></event>
<event name="ev2" source="source_window"><![CDATA[var_number==number and direction=='IN']]></event>
</events>
<logic><![CDATA[fby{7200 seconds}(ev1, ev2)]]></logic>
Thanks.
You could use a compute window to get the difference between two timestamp fields. It appears that the difference (timestamp2-timestamp1) is returned in days. Multiply by 86400 to get seconds.
difference=(timestamp2-timestamp1)*86400
The difference field should have type double. Or integer for truncated results.
If Robert's suggestion doesn't work for your needs, I think this is the correct way to write the pattern I was trying to create before:
FBY{30 minutes}(FBY{10 minutes}(anyEvent,e1),e2)
Another approach is to code the lower bound of the time frame in the second event of interest. This example looks for e2 to occur between 10 and 30 minutes after e1. (10 min is equivalent to 0.00694444 days).
<events>
<event source="Src" name="e1"><![CDATA[direction=='OUT' and var_number==number
and var_timestamp==timestamp]]></event>
<event source="Src" name="e2"><![CDATA[direction=="IN" and var_number==number
and var_timestamp<timestamp - 0.00694444]]></event>
</events>
<logic>fby{1800 seconds}(e1, e2)</logic>
As a follow up , the difference (in seconds) between two timestamp fields can be calculated in the functional window with the following:
<function name="difference"><![CDATA[product(diff($timestamp2, $timestamp1), 0.000001)]]></function>
Here, “difference” is type double.
Hi.
Currently the solution provided by Robert works. Not sure why your's doesn't work correctly or if I am doing something differently as supposed to. The higher boundary is working but lower boundary is not taken into consideration so events under this boundary still activate patterns.
I'm glad you found a solution. I'll do some tests when I get a chance. Good luck
COURBE D'ANALYSE
Whether you're already using SAS Event Stream Processing or thinking about it, this is where you can connect with your peers, ask questions and find resources.
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.