<?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: Detecting overlapping times in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Detecting-overlapping-times/m-p/614334#M179556</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/22295"&gt;@RVA&lt;/a&gt;&amp;nbsp; Thank you for posting the input sample. What is the corresponding output sample for the input sample?&lt;/P&gt;</description>
    <pubDate>Mon, 30 Dec 2019 02:38:55 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-12-30T02:38:55Z</dc:date>
    <item>
      <title>Detecting overlapping times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Detecting-overlapping-times/m-p/614332#M179555</link>
      <description>&lt;P&gt;Dear all&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following data.&amp;nbsp; What do I need to do to flag rows 1 and 2 as they indeed happen at the same days and time (overlapping)?&amp;nbsp; I have been thinking but still cannot come up with SAS scripts to flag those two rows.&amp;nbsp; Any help is much appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="466px"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="106.667px"&gt;Course section&lt;/TD&gt;
&lt;TD width="106.667px"&gt;Meeting_days&lt;/TD&gt;
&lt;TD width="96.6667px"&gt;Beginning_time&lt;/TD&gt;
&lt;TD width="96.6667px"&gt;Ending_time&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="106.667px"&gt;CHEM 100 001&lt;/TD&gt;
&lt;TD width="106.667px"&gt;MWF&lt;/TD&gt;
&lt;TD width="96.6667px"&gt;13:00&lt;/TD&gt;
&lt;TD width="96.6667px"&gt;13:45&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="106.667px"&gt;CHEM 100 007&lt;/TD&gt;
&lt;TD width="106.667px"&gt;MWF&lt;/TD&gt;
&lt;TD width="96.6667px"&gt;13:15&lt;/TD&gt;
&lt;TD width="96.6667px"&gt;13:45&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="106.667px"&gt;CHEM 100 010&lt;/TD&gt;
&lt;TD width="106.667px"&gt;MWF&lt;/TD&gt;
&lt;TD width="96.6667px"&gt;14:00&lt;/TD&gt;
&lt;TD width="96.6667px"&gt;16:00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="106.667px"&gt;CHEM 100 021&lt;/TD&gt;
&lt;TD width="106.667px"&gt;MWF&lt;/TD&gt;
&lt;TD width="96.6667px"&gt;9:00&lt;/TD&gt;
&lt;TD width="96.6667px"&gt;10:00&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Mon, 30 Dec 2019 01:43:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Detecting-overlapping-times/m-p/614332#M179555</guid>
      <dc:creator>RVA</dc:creator>
      <dc:date>2019-12-30T01:43:45Z</dc:date>
    </item>
    <item>
      <title>Re: Detecting overlapping times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Detecting-overlapping-times/m-p/614334#M179556</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/22295"&gt;@RVA&lt;/a&gt;&amp;nbsp; Thank you for posting the input sample. What is the corresponding output sample for the input sample?&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2019 02:38:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Detecting-overlapping-times/m-p/614334#M179556</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-12-30T02:38:55Z</dc:date>
    </item>
    <item>
      <title>Re: Detecting overlapping times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Detecting-overlapping-times/m-p/614335#M179557</link>
      <description>&lt;P&gt;&lt;FONT face="courier new,courier"&gt;brute force method - here is your algorithm (no SAS code)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;make a data structure for every minute for the days of interest&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;mo0001-mo2359&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;tu0000-tu2359&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;if your data is limited to say 800 to 1800 your minutes array can be smaller&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;set all values to zero&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;take each row - use the start and end time to add 100 to each minute value&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;once you have processed all your rows, any values of your minute values GT 100 have overlaps&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;how many rows do you expect ?&amp;nbsp; put an integer on each row and add that to your minute flags&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;if I get a free hour or so I may be able to come up with some code&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;I recommend not using "scripts" to describe your work in SAS - use programs or code.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;IMHO it "cheapens" your efforts.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Bob B, Somerset NJ&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2019 02:41:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Detecting-overlapping-times/m-p/614335#M179557</guid>
      <dc:creator>blueroad</dc:creator>
      <dc:date>2019-12-30T02:41:26Z</dc:date>
    </item>
    <item>
      <title>Re: Detecting overlapping times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Detecting-overlapping-times/m-p/614355#M179564</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/22295"&gt;@RVA&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks that the comparison has to be made with all records to decide the match. Here is a way where the records are matched and if found to have overlapping records then their RID (Record IDs in terms of _N_) is output. I have modified your input data with some more overlapping records to verify my code. Here is the augmented data set and the program. The approach is to note the Beginning, Ending times and the RID for the first record. The subsequent records are then compared with the previous values and if there is an overlap then the corresponding RIDs are output. If there is no overlap, the current record will be stored as previous values, prevRid taking the current _N_.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;CHEM100  001 MWF 13:00 13:45
CHEM100  007 MWF 13:15 13:45
CHEM100  007 MWF 13:35 13:40
CHEM100  010 MWF 14:00 16:00
CHEM100  010 MWF 15:00 15:30
CHEM100  021 MWF  9:00 10:00
CHEM100  025 MWF  9:30 10:00&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want;
   do i = 1 by 1 until(eof);
      set have end = eof;
      if prevB = . then do; 
         prevB = Beginning_time;
         prevE = Ending_time;
         prevRid = i; 
      end;
      else do;
         if prevB &amp;lt;= Beginning_time and prevE &amp;gt;= Ending_time then do;
            nextRid = i;
            output;
         end;
         else do;
            prevB = Beginning_time;
            prevE = Ending_time;
            prevRid = i;
         end;
      end;
   end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The output is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture_01.JPG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/35079iAADFDBD9B8EB4527/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture_01.JPG" alt="Capture_01.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2019 07:09:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Detecting-overlapping-times/m-p/614355#M179564</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2019-12-30T07:09:27Z</dc:date>
    </item>
    <item>
      <title>Re: Detecting overlapping times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Detecting-overlapping-times/m-p/614359#M179565</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/22295"&gt;@RVA&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My previous program assumes that the overlapping records are placed one-after the other. What if the overlapping records are randomly placed?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the overlapping record happens to fall anywhere (not to next) then my previous code can be revised using POINT= option of SET statement. The algorithm is to to select the i-th record and compare it with all records starting from i+1, until the end of the data set. If there is a overlap, then output the Record IDs of both the records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have reordered some of the overlapping records as shown below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;CHEM100  001 MWF 13:00 13:45
CHEM100  007 MWF 13:35 13:40
CHEM100  010 MWF 14:00 16:00
CHEM100  021 MWF  9:00 10:00
CHEM100  025 MWF  9:30 10:00
CHEM100  007 MWF 13:15 13:45
CHEM100  010 MWF 15:00 15:30&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The revised program:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   do i = 1 to n - 1;
      set have nobs = n point = i; 
         prevB = Beginning_time;
         prevE = Ending_time;
         prevRid = i; 

      do j = i + 1 to n;
         set have point = j;
         if prevB &amp;lt;= Beginning_time and prevE &amp;gt;= Ending_time then do;
            nextRid = j;
            output;
         end;
      end;
   end;
stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The OUPUT Is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture_01.JPG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/35080i44AC2FC37AB62275/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture_01.JPG" alt="Capture_01.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2019 08:21:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Detecting-overlapping-times/m-p/614359#M179565</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2019-12-30T08:21:58Z</dc:date>
    </item>
    <item>
      <title>Re: Detecting overlapping times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Detecting-overlapping-times/m-p/614387#M179578</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/22295"&gt;@RVA&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is my attempt. Let me know!&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input Course_section $ 1-12 Meeting_days $ 14-16 Beginning_time Ending_time;
	informat Beginning_time Ending_time time10.;
	format Beginning_time Ending_time time10.;
	datalines;
CHEM 100 001 MWF 13:00 13:45
CHEM 100 007 MWF 13:15 13:45
CHEM 100 010 MWF 14:00 16:00
CHEM 100 021 MWF 9:00  10:00&lt;BR /&gt;;
run;

proc sort data=have;
	by Meeting_days Beginning_time;
run;

data have2;
	set have;
	by Meeting_days;
	format _lag time10.;
	_lag = lag(Ending_time);
	if first.Meeting_days then _lag=.;
	if _lag &amp;gt;= Beginning_time then flag = 1;
	else flag=0;
	drop _lag;
run;

data want;
	merge have2 have2 (firstobs=2 keep=flag rename=(flag=flag_lead));
	if flag=0 and flag_lead=1 then flag=1;
	drop flag_lead;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Output:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="Capture d’écran 2019-12-30 à 14.34.00.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/35084i66A93A374203CDCD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Capture d’écran 2019-12-30 à 14.34.00.png" alt="Capture d’écran 2019-12-30 à 14.34.00.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2019 13:34:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Detecting-overlapping-times/m-p/614387#M179578</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2019-12-30T13:34:42Z</dc:date>
    </item>
    <item>
      <title>Re: Detecting overlapping times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Detecting-overlapping-times/m-p/615652#M180098</link>
      <description>&lt;P&gt;Dear all&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you so much for your help.&amp;nbsp; Let me plug your scripts in and run them on my data.&amp;nbsp; I'll get back if I have any questions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Much appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2020 13:17:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Detecting-overlapping-times/m-p/615652#M180098</guid>
      <dc:creator>RVA</dc:creator>
      <dc:date>2020-01-07T13:17:45Z</dc:date>
    </item>
  </channel>
</rss>

