<?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: How to find if the start and stop date for an employee conflicts with other observations for tha in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-if-the-start-and-stop-date-for-an-employee-conflicts/m-p/734858#M228922</link>
    <description>&lt;P&gt;I presume a "conflict" is when any pair of records (for a given id) overlap.&amp;nbsp; I.e., you want to compare each pair of records having the same id.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can do that in a data step by maintaining 2 arrays:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;HISTORY array.&amp;nbsp; 2-dimensions:&amp;nbsp; the first dimension has a row for each observation (I specify up to 10 rows below), the second dimension for all possible dates in your dataset (I specify 01jan2014 through 31mar2021).&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;CONFLICTS array:&amp;nbsp; It's has a row for each obs, and a column for each obs.&amp;nbsp; If obs i and obs j overlap, then CONFLICTS{i,j}=1&amp;nbsp; (but not conflicts{j,i}.&amp;nbsp; So at the end of each id, just sum up the elements of the array:&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards expandtabs truncover;
input Employeeid	start_dt : mmddyy10.	stop_dt :mmddyy10.;
format start_dt stop_dt mmddyy10.;
cards;
123	1/1/2014	4/1/2015
123	3/1/2015	12/31/2016
123	6/1/2018	12/2/2020
123	1/2/2021	 
222	1/1/2020	12/3/2020
222	4/2/2019	12/31/2019
333	1/1/2018	12/31/2019
333	1/2/2018	12/31/2019
333	1/3/2018	12/31/2020
;

data want (keep=employeeid n_conflicts);
  array history{10,%sysevalf("01jan2014"d):%sysevalf("31mar2021"d)};
  array conflicts{10,10};

  do i=1 by 1 until (last.employeeid);
    set have;
    by employeeid;

    do d=start_dt to coalesce(stop_dt,start_dt);
      history{i,d}=1;
      if i&amp;gt;1 then do j=1 to i-1;
        if history{j,d}^=. then conflicts{i,j}=1;
      end;
    end;
  end;
  n_conflicts=sum(0,of conflicts{*});
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You have an obs with no stop_dt.&amp;nbsp; This program assumes stop_dt=start_dt in such a case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you expect up to 20 obs per id, then increase the array size accordingly (both HISTORY and CONFLICTS).&amp;nbsp; And if your date range is greater the jan2014-mar2021, just change the corresponding limits in the HISTORY array.&lt;/P&gt;</description>
    <pubDate>Sat, 17 Apr 2021 05:42:52 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2021-04-17T05:42:52Z</dc:date>
    <item>
      <title>How to find if the start and stop date for an employee conflicts with other observations for that id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-if-the-start-and-stop-date-for-an-employee-conflicts/m-p/734411#M228798</link>
      <description>&lt;P&gt;I have a dataset with start and stop dates for employees.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Employee id&lt;/TD&gt;&lt;TD&gt;start_dt&lt;/TD&gt;&lt;TD&gt;stop_dt&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;1/1/2014&lt;/TD&gt;&lt;TD&gt;4/1/2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;3/1/2015&lt;/TD&gt;&lt;TD&gt;12/31/2016&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;6/1/2018&lt;/TD&gt;&lt;TD&gt;12/2/2020&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;1/2/2021&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;222&lt;/TD&gt;&lt;TD&gt;1/1/2020&lt;/TD&gt;&lt;TD&gt;12/3/2020&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;222&lt;/TD&gt;&lt;TD&gt;4/2/2019&lt;/TD&gt;&lt;TD&gt;12/31/2019&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;333&lt;/TD&gt;&lt;TD&gt;1/1/2018&lt;/TD&gt;&lt;TD&gt;12/31/2019&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;333&lt;/TD&gt;&lt;TD&gt;1/2/2018&lt;/TD&gt;&lt;TD&gt;12/31/2019&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;333&lt;/TD&gt;&lt;TD&gt;1/3/2018&lt;/TD&gt;&lt;TD&gt;12/31/2020&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;I want to find out how many concurrent time periods are in above dataset for each employee.&lt;/SPAN&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Employee id&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Conflicts&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;222&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;333&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Apr 2021 18:53:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-if-the-start-and-stop-date-for-an-employee-conflicts/m-p/734411#M228798</guid>
      <dc:creator>smorijawala</dc:creator>
      <dc:date>2021-04-15T18:53:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to find if the start and stop date for an employee conflicts with other observations for tha</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-if-the-start-and-stop-date-for-an-employee-conflicts/m-p/734603#M228813</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Please supply usable data, as code.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this should work. Adapt to your needs.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  select ID, sum(a.START&amp;lt;=b.START&amp;lt;=a.END)
  from (select * from HAVE a, HAVE b
        where a.ID=b.ID and a.START &amp;lt; b.START)
  group by ID;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Apr 2021 22:27:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-if-the-start-and-stop-date-for-an-employee-conflicts/m-p/734603#M228813</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-04-15T22:27:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to find if the start and stop date for an employee conflicts with other observations for tha</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-if-the-start-and-stop-date-for-an-employee-conflicts/m-p/734713#M228869</link>
      <description>&lt;P&gt;How do you define CONFLICTS ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
infile cards expandtabs truncover;
input Employeeid	start_dt : mmddyy10.	stop_dt :mmddyy10.;
format start_dt stop_dt mmddyy10.;
cards;
123	1/1/2014	4/1/2015
123	3/1/2015	12/31/2016
123	6/1/2018	12/2/2020
123	1/2/2021	 
222	1/1/2020	12/3/2020
222	4/2/2019	12/31/2019
333	1/1/2018	12/31/2019
333	1/2/2018	12/31/2019
333	1/3/2018	12/31/2020
;
data temp;
 set have;
 by Employeeid;
 if first.Employeeid then n=0;
 n+1;

 if not missing(start_dt) and not missing(stop_dt) then do;
  do date=start_dt to stop_dt;
   output;
  end;
 end;
 else do; date=start_dt;output;end;
 keep  Employeeid date n;
 format date mmddyy10.;
run;

proc sql;
create table temp1 as
select  Employeeid, date , count(distinct n) as n
 from temp
  group by Employeeid, date;

create table want as
select Employeeid, max(n)-1 as conflicts
 from temp1
  group by Employeeid;
quit;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Apr 2021 12:24:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-if-the-start-and-stop-date-for-an-employee-conflicts/m-p/734713#M228869</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-04-16T12:24:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to find if the start and stop date for an employee conflicts with other observations for tha</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-if-the-start-and-stop-date-for-an-employee-conflicts/m-p/734858#M228922</link>
      <description>&lt;P&gt;I presume a "conflict" is when any pair of records (for a given id) overlap.&amp;nbsp; I.e., you want to compare each pair of records having the same id.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can do that in a data step by maintaining 2 arrays:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;HISTORY array.&amp;nbsp; 2-dimensions:&amp;nbsp; the first dimension has a row for each observation (I specify up to 10 rows below), the second dimension for all possible dates in your dataset (I specify 01jan2014 through 31mar2021).&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;CONFLICTS array:&amp;nbsp; It's has a row for each obs, and a column for each obs.&amp;nbsp; If obs i and obs j overlap, then CONFLICTS{i,j}=1&amp;nbsp; (but not conflicts{j,i}.&amp;nbsp; So at the end of each id, just sum up the elements of the array:&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards expandtabs truncover;
input Employeeid	start_dt : mmddyy10.	stop_dt :mmddyy10.;
format start_dt stop_dt mmddyy10.;
cards;
123	1/1/2014	4/1/2015
123	3/1/2015	12/31/2016
123	6/1/2018	12/2/2020
123	1/2/2021	 
222	1/1/2020	12/3/2020
222	4/2/2019	12/31/2019
333	1/1/2018	12/31/2019
333	1/2/2018	12/31/2019
333	1/3/2018	12/31/2020
;

data want (keep=employeeid n_conflicts);
  array history{10,%sysevalf("01jan2014"d):%sysevalf("31mar2021"d)};
  array conflicts{10,10};

  do i=1 by 1 until (last.employeeid);
    set have;
    by employeeid;

    do d=start_dt to coalesce(stop_dt,start_dt);
      history{i,d}=1;
      if i&amp;gt;1 then do j=1 to i-1;
        if history{j,d}^=. then conflicts{i,j}=1;
      end;
    end;
  end;
  n_conflicts=sum(0,of conflicts{*});
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You have an obs with no stop_dt.&amp;nbsp; This program assumes stop_dt=start_dt in such a case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you expect up to 20 obs per id, then increase the array size accordingly (both HISTORY and CONFLICTS).&amp;nbsp; And if your date range is greater the jan2014-mar2021, just change the corresponding limits in the HISTORY array.&lt;/P&gt;</description>
      <pubDate>Sat, 17 Apr 2021 05:42:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-if-the-start-and-stop-date-for-an-employee-conflicts/m-p/734858#M228922</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-04-17T05:42:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to find if the start and stop date for an employee conflicts with other observations for tha</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-if-the-start-and-stop-date-for-an-employee-conflicts/m-p/735323#M229073</link>
      <description>Thank you so much!</description>
      <pubDate>Mon, 19 Apr 2021 17:25:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-if-the-start-and-stop-date-for-an-employee-conflicts/m-p/735323#M229073</guid>
      <dc:creator>smorijawala</dc:creator>
      <dc:date>2021-04-19T17:25:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to find if the start and stop date for an employee conflicts with other observations for tha</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-find-if-the-start-and-stop-date-for-an-employee-conflicts/m-p/735324#M229074</link>
      <description>&lt;P&gt;This works! Thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 19 Apr 2021 17:27:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-find-if-the-start-and-stop-date-for-an-employee-conflicts/m-p/735324#M229074</guid>
      <dc:creator>smorijawala</dc:creator>
      <dc:date>2021-04-19T17:27:18Z</dc:date>
    </item>
  </channel>
</rss>

