BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Rain
Obsidian | Level 7

Hi.

Maybe someone can share tips or suggestions how to complete following use case:

 

  • I need to detect a pattern that occurs between certain time frame. For example after 10 minutes but before 30 minutes.

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

1 ACCEPTED SOLUTION

Accepted Solutions
RLigtenberg
SAS Employee

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.

View solution in original post

9 REPLIES 9
StephenFoerster
SAS Employee

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>

   ...

Senior Manager ● Global Enablement and Learning
Technology Transfer and Governance, R&D
Tel: + 1 919 531-1402 ● stephen.foerster@sas.com
Worldwide Headquarters ● Cary, NC

www.sas.com
SAS® … THE POWER TO KNOW®

Rain
Obsidian | Level 7

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.

RLigtenberg
SAS Employee

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.

StephenFoerster
SAS Employee

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)

 

 

Senior Manager ● Global Enablement and Learning
Technology Transfer and Governance, R&D
Tel: + 1 919 531-1402 ● stephen.foerster@sas.com
Worldwide Headquarters ● Cary, NC

www.sas.com
SAS® … THE POWER TO KNOW®

RLigtenberg
SAS Employee

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.

Rain
Obsidian | Level 7

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.

StephenFoerster
SAS Employee

I'm glad you found a solution.  I'll do some tests when I get a chance.  Good luck

Senior Manager ● Global Enablement and Learning
Technology Transfer and Governance, R&D
Tel: + 1 919 531-1402 ● stephen.foerster@sas.com
Worldwide Headquarters ● Cary, NC

www.sas.com
SAS® … THE POWER TO KNOW®

koffi222
Calcite | Level 5

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.

 

Multiple Linear Regression in SAS

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.

Discussion stats
  • 9 replies
  • 3486 views
  • 1 like
  • 4 in conversation