<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Counting concurrency and grouping per event in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Counting-concurrency-and-grouping-per-event/m-p/648508#M194284</link>
    <description>&lt;P&gt;Good lord, you've put just as much effort into that reply as I put into creating and debugging the process on Friday. I ran it and it's perfect ,thank-you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now all I have to do is learn how it works and keep it in mind for future usage.&lt;/P&gt;</description>
    <pubDate>Mon, 18 May 2020 10:23:30 GMT</pubDate>
    <dc:creator>_Dan_</dc:creator>
    <dc:date>2020-05-18T10:23:30Z</dc:date>
    <item>
      <title>Counting concurrency and grouping per event</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-concurrency-and-grouping-per-event/m-p/648000#M194000</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to report on concurrent groups of events. We capture data every 15 minutes across 7 Servers / 14 Work spaces. I'm tracking where there's 100% utilisation of any of those 14 Work spaces.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The Concurrency flag is done. I have a '1' where an event existed for two or more rows (two or more 15 minute periods). Simple SQL - most likely a lag/lead way to do it, but this works. Basically the _Get dataset has the original RunDtTm, plus two more columns where the RunDtTm has been shifted forward by 15 minutes (RunDtTm15), or backwards by 15 minutes (RunDtTm15_).&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table _Stage as
		select
			datepart(o.RunDtTm) as RunDt format DDMMYY10.
			,o.RunDtTm
			,case when coalesce(b.RunDtTm,f.RunDtTm) is not null then 1 else 0 end as Concurrent
			,o.Server
			,o.WorkFolder
			,o.Use_pct
		from
			_Get		o	left join
			_Get		f	on o.RunDtTm = f.RunDtTm15 and o.Server = f.Server and o.WorkFolder = f.WorkFolder left join
			_Get		b	on o.RunDtTm = b.RunDtTm15_ and o.Server = b.Server and o.WorkFolder = b.WorkFolder 
;quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I now need is a flag that counts how many times per day a record exists, but, counts concurrent records as one. Here's the data I have right now. The best example would be 22/04/2020, Server03, work2 - there were three events, but two were concurrent episodes.&lt;/P&gt;&lt;P&gt;Event 1:&amp;nbsp;22APR2020:09:00:00&lt;/P&gt;&lt;P&gt;Event 2:&amp;nbsp;22APR2020:10:30:00 -&amp;nbsp;22APR2020:11:00:00&lt;/P&gt;&lt;P&gt;Event 3:&amp;nbsp;22APR2020:11:15:00 -&amp;nbsp;22APR2020:12:00:00&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And thus the new column would show 1, 2, 2, 2, 3, 3, 3, 3.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the contents of the data _Stage from the above query.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA WORK._STAGE;
    LENGTH
        RunDt              8
        RunDtTm            8
        Concurrent         8
        Server           $ 8
        WorkFolder       $ 5
        Use_pct          $ 4 ;
    FORMAT
        RunDt            DDMMYY10.
        RunDtTm          DATETIME18.
        Concurrent       BEST1.
        Server           $CHAR8.
        WorkFolder       $CHAR5.
        Use_pct          $CHAR4. ;
    INFORMAT
        RunDt            DDMMYY10.
        RunDtTm          DATETIME18.
        Concurrent       BEST1.
        Server           $CHAR8.
        WorkFolder       $CHAR5.
        Use_pct          $CHAR4. ;
    INFILE DATALINES4
        DLM='7F'x
        MISSOVER
        DSD ;
    INPUT
        RunDt            : ?? DDMMYY10.
        RunDtTm          : ?? ANYDTDTM18.
        Concurrent       : ?? BEST1.
        Server           : $CHAR8.
        WorkFolder       : $CHAR5.
        Use_pct          : $CHAR4. ;
DATALINES4;
02/04/2020&amp;#127;02APR2020:16:00:00&amp;#127;0&amp;#127;server06&amp;#127;work2&amp;#127;100%
03/04/2020&amp;#127;03APR2020:09:30:00&amp;#127;0&amp;#127;server07&amp;#127;work2&amp;#127;100%
07/04/2020&amp;#127;07APR2020:09:45:00&amp;#127;0&amp;#127;server03&amp;#127;work2&amp;#127;100%
07/04/2020&amp;#127;07APR2020:18:45:00&amp;#127;0&amp;#127;server06&amp;#127;work1&amp;#127;100%
08/04/2020&amp;#127;08APR2020:11:00:00&amp;#127;0&amp;#127;server06&amp;#127;work2&amp;#127;100%
08/04/2020&amp;#127;08APR2020:11:30:00&amp;#127;0&amp;#127;server06&amp;#127;work2&amp;#127;100%
09/04/2020&amp;#127;09APR2020:09:30:00&amp;#127;0&amp;#127;server02&amp;#127;work2&amp;#127;100%
09/04/2020&amp;#127;09APR2020:19:45:00&amp;#127;0&amp;#127;server06&amp;#127;work2&amp;#127;100%
13/04/2020&amp;#127;13APR2020:14:00:00&amp;#127;0&amp;#127;server02&amp;#127;work2&amp;#127;100%
14/04/2020&amp;#127;14APR2020:15:45:00&amp;#127;0&amp;#127;server02&amp;#127;work2&amp;#127;100%
14/04/2020&amp;#127;14APR2020:15:45:00&amp;#127;0&amp;#127;server05&amp;#127;work2&amp;#127;100%
15/04/2020&amp;#127;15APR2020:07:45:00&amp;#127;0&amp;#127;server03&amp;#127;work2&amp;#127;100%
15/04/2020&amp;#127;15APR2020:09:15:00&amp;#127;0&amp;#127;server02&amp;#127;work2&amp;#127;100%
15/04/2020&amp;#127;15APR2020:11:15:00&amp;#127;0&amp;#127;server03&amp;#127;work2&amp;#127;100%
16/04/2020&amp;#127;16APR2020:09:00:00&amp;#127;1&amp;#127;server03&amp;#127;work2&amp;#127;100%
16/04/2020&amp;#127;16APR2020:09:15:00&amp;#127;1&amp;#127;server03&amp;#127;work2&amp;#127;100%
16/04/2020&amp;#127;16APR2020:09:30:00&amp;#127;1&amp;#127;server03&amp;#127;work2&amp;#127;100%
16/04/2020&amp;#127;16APR2020:09:45:00&amp;#127;1&amp;#127;server03&amp;#127;work2&amp;#127;100%
16/04/2020&amp;#127;16APR2020:11:15:00&amp;#127;0&amp;#127;server03&amp;#127;work2&amp;#127;100%
16/04/2020&amp;#127;16APR2020:12:00:00&amp;#127;0&amp;#127;server03&amp;#127;work1&amp;#127;100%
17/04/2020&amp;#127;17APR2020:09:00:00&amp;#127;0&amp;#127;server02&amp;#127;work2&amp;#127;100%
20/04/2020&amp;#127;20APR2020:09:15:00&amp;#127;0&amp;#127;server05&amp;#127;work1&amp;#127;100%
20/04/2020&amp;#127;20APR2020:12:00:00&amp;#127;0&amp;#127;server06&amp;#127;work2&amp;#127;100%
22/04/2020&amp;#127;22APR2020:09:00:00&amp;#127;0&amp;#127;server03&amp;#127;work2&amp;#127;100%
22/04/2020&amp;#127;22APR2020:10:30:00&amp;#127;1&amp;#127;server03&amp;#127;work2&amp;#127;100%
22/04/2020&amp;#127;22APR2020:10:45:00&amp;#127;1&amp;#127;server03&amp;#127;work2&amp;#127;100%
22/04/2020&amp;#127;22APR2020:11:00:00&amp;#127;1&amp;#127;server03&amp;#127;work2&amp;#127;100%
22/04/2020&amp;#127;22APR2020:11:15:00&amp;#127;0&amp;#127;server02&amp;#127;work2&amp;#127;100%
22/04/2020&amp;#127;22APR2020:11:15:00&amp;#127;1&amp;#127;server03&amp;#127;work2&amp;#127;100%
22/04/2020&amp;#127;22APR2020:11:30:00&amp;#127;1&amp;#127;server03&amp;#127;work2&amp;#127;100%
22/04/2020&amp;#127;22APR2020:11:45:00&amp;#127;1&amp;#127;server03&amp;#127;work2&amp;#127;100%
22/04/2020&amp;#127;22APR2020:12:00:00&amp;#127;1&amp;#127;server03&amp;#127;work2&amp;#127;100%
23/04/2020&amp;#127;23APR2020:04:45:00&amp;#127;0&amp;#127;server02&amp;#127;work1&amp;#127;100%
23/04/2020&amp;#127;23APR2020:14:15:00&amp;#127;0&amp;#127;server04&amp;#127;work2&amp;#127;100%
24/04/2020&amp;#127;24APR2020:12:30:00&amp;#127;0&amp;#127;server06&amp;#127;work1&amp;#127;100%
27/04/2020&amp;#127;27APR2020:04:30:00&amp;#127;0&amp;#127;server03&amp;#127;work2&amp;#127;100%
28/04/2020&amp;#127;28APR2020:08:15:00&amp;#127;0&amp;#127;server03&amp;#127;work1&amp;#127;100%
28/04/2020&amp;#127;28APR2020:10:30:00&amp;#127;1&amp;#127;server05&amp;#127;work2&amp;#127;100%
28/04/2020&amp;#127;28APR2020:10:45:00&amp;#127;1&amp;#127;server05&amp;#127;work2&amp;#127;100%
28/04/2020&amp;#127;28APR2020:13:00:00&amp;#127;0&amp;#127;server04&amp;#127;work2&amp;#127;100%
28/04/2020&amp;#127;28APR2020:17:15:00&amp;#127;0&amp;#127;server07&amp;#127;work2&amp;#127;100%
29/04/2020&amp;#127;29APR2020:07:15:00&amp;#127;0&amp;#127;server06&amp;#127;work2&amp;#127;100%
29/04/2020&amp;#127;29APR2020:14:30:00&amp;#127;0&amp;#127;server05&amp;#127;work2&amp;#127;100%
29/04/2020&amp;#127;29APR2020:15:15:00&amp;#127;0&amp;#127;server03&amp;#127;work2&amp;#127;100%
30/04/2020&amp;#127;30APR2020:11:30:00&amp;#127;0&amp;#127;server06&amp;#127;work2&amp;#127;100%
30/04/2020&amp;#127;30APR2020:14:15:00&amp;#127;0&amp;#127;server06&amp;#127;work1&amp;#127;100%
30/04/2020&amp;#127;30APR2020:16:00:00&amp;#127;0&amp;#127;server03&amp;#127;work1&amp;#127;100%
;;;;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's what I want it to look like (take note of entry 5 which is a different Sever, and hence the Concurrent_Count is 1):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;RunDt	RunDtTm	Concurrent	Server	WorkFolder	Use_pct   Concurrent_Count
22/04/2020	22APR2020:09:00:00	0	geniegrid03	/sas/workb	100%     1
22/04/2020	22APR2020:10:30:00	1	geniegrid03	/sas/workb	100%     2
22/04/2020	22APR2020:10:45:00	1	geniegrid03	/sas/workb	100%     2
22/04/2020	22APR2020:11:00:00	1	geniegrid03	/sas/workb	100%     2
22/04/2020	22APR2020:11:15:00	0	geniegrid02	/sas/workb	100%     1
22/04/2020	22APR2020:11:15:00	1	geniegrid03	/sas/workb	100%     3
22/04/2020	22APR2020:11:30:00	1	geniegrid03	/sas/workb	100%     3
22/04/2020	22APR2020:11:45:00	1	geniegrid03	/sas/workb	100%     3
22/04/2020	22APR2020:12:00:00	1	geniegrid03	/sas/workb	100%     3&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 May 2020 12:03:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-concurrency-and-grouping-per-event/m-p/648000#M194000</guid>
      <dc:creator>_Dan_</dc:creator>
      <dc:date>2020-05-15T12:03:24Z</dc:date>
    </item>
    <item>
      <title>Re: Counting concurrency and grouping per event</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-concurrency-and-grouping-per-event/m-p/648095#M194066</link>
      <description>&lt;P&gt;You are having different concurrent_count values tracked for different servers.&amp;nbsp; You explanation shows the count increasing, so in this answer that value will be called &lt;CODE&gt;seq&lt;/CODE&gt; for sequence&amp;nbsp; Server is a character value, and tracking by value can be easily done using a HASH object.&amp;nbsp; They key is the `server` and the data is the `seq` that may or may not get incremented according to your rules.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The hash should be cleared at the start of the date when the sequence counting is reset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data is presumed to be in a timestamp order essential to sequence count computation.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;data want;
  if 0 then set _STAGE;

  if _n_ = 1 then do;
    declare hash cc();
    cc.defineKey('server');
    cc.defineData('seq');
    cc.defineDone();
    call missing(seq);  * prevent warning;
    pserver = server;   * prep pdv;
  end; 

  cc.clear();

  pserver = '';  * act as a LAG var for server;
  pflag = .;     * act as a LAG var for concurrent flag;

  * one day at a time;

  do until (last.rundt);
    set _STAGE;
    by rundt;

    rc = cc.find();  * side effect is that seq for server retrieved from hash;

    if pserver ne server then do;   * server changed from prior row;
      if rc ne 0 
        then seq = 1;  * first time for server;
        else seq + 1;  * first time for server in a subsequent run, seq+1 regardless of concurrent;
    end;
    else do;
      /* same server as prior row */
      /* a hash entry MUST exist if code flow reaches here */
      /* which means seq is value for current server       */
      if concurrent = 0 then 
        seq + 1;            * not concurrent always increases seq;
      else
        seq + (pflag = 0);  * concurrent run of 0 1 becomes seq+1, and 1 1 gets seq+0;
    end;

    cc.replace(); * save seq count for server;

    OUTPUT;

    pflag = concurrent;  * update prior value tracking variables (lag emulation);
    pserver = server;

    drop rc pflag pserver;
  end;
run;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Happy counting!&lt;/P&gt;</description>
      <pubDate>Fri, 15 May 2020 16:47:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-concurrency-and-grouping-per-event/m-p/648095#M194066</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-05-15T16:47:03Z</dc:date>
    </item>
    <item>
      <title>Re: Counting concurrency and grouping per event</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Counting-concurrency-and-grouping-per-event/m-p/648508#M194284</link>
      <description>&lt;P&gt;Good lord, you've put just as much effort into that reply as I put into creating and debugging the process on Friday. I ran it and it's perfect ,thank-you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now all I have to do is learn how it works and keep it in mind for future usage.&lt;/P&gt;</description>
      <pubDate>Mon, 18 May 2020 10:23:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Counting-concurrency-and-grouping-per-event/m-p/648508#M194284</guid>
      <dc:creator>_Dan_</dc:creator>
      <dc:date>2020-05-18T10:23:30Z</dc:date>
    </item>
  </channel>
</rss>

