<?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: dealing with time periods with start and end date and overlap in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/dealing-with-time-periods-with-start-and-end-date-and-overlap/m-p/316261#M61710</link>
    <description>&lt;P&gt;Ignoring patients ids, I am just trying to get aggregate numbers over a large data. I want to know the total number of prescriptions that overlap for 30 days or more.&amp;nbsp;&lt;/P&gt;&lt;P&gt;If two medications overlap, then 2&amp;nbsp;&lt;/P&gt;&lt;P&gt;if three medications overlap 3.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output above shows the classes that overlaped. so for 2 a-b and so on&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 02 Dec 2016 14:44:00 GMT</pubDate>
    <dc:creator>lillymaginta</dc:creator>
    <dc:date>2016-12-02T14:44:00Z</dc:date>
    <item>
      <title>dealing with time periods with start and end date and overlap</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/dealing-with-time-periods-with-start-and-end-date-and-overlap/m-p/316012#M61699</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;drug   start                    end
a        01/01/2001    02/15/2001
b        01/02/2001    02/10/2001
c        04/05/2002     06/07/2002
d        04/15/2002     07/01/2002
e       04/01/2002      07/18/2002
f       04/05/2002      06/01/2002 &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want to report drug that overlapped&amp;nbsp;by 30 days or more.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output:&amp;nbsp;&lt;/P&gt;&lt;P&gt;a-b&lt;/P&gt;&lt;P&gt;c-d-e-f&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2016 17:20:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/dealing-with-time-periods-with-start-and-end-date-and-overlap/m-p/316012#M61699</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2016-12-01T17:20:55Z</dc:date>
    </item>
    <item>
      <title>Re: dealing with time periods with start and end date and overlap</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/dealing-with-time-periods-with-start-and-end-date-and-overlap/m-p/316065#M61701</link>
      <description>&lt;P&gt;There could be many interpretations to your sample data. To help clarify things, what would you expect for the data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;a 2002/01/01 2002/01/31
b 2002/01/01 2002/12/31
c 2002/12/01 2002/12/31
d 2002/06/01 2003/06/30&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Dec 2016 19:45:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/dealing-with-time-periods-with-start-and-end-date-and-overlap/m-p/316065#M61701</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-12-01T19:45:07Z</dc:date>
    </item>
    <item>
      <title>Re: dealing with time periods with start and end date and overlap</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/dealing-with-time-periods-with-start-and-end-date-and-overlap/m-p/316225#M61709</link>
      <description>&lt;PRE&gt;

data have;
input drug  $ start : mmddyy10.    end : mmddyy10.;
format start end mmddyy10.;
cards;
a        01/01/2001    02/15/2001
b        01/02/2001    02/10/2001
c        04/05/2002     06/07/2002
d        04/15/2002     07/01/2002
e       04/01/2002      07/18/2002
f       04/05/2002      06/01/2002 
;
run;

data have;
 set have;
 dif=lag(end)-start;
 if dif lt 30 then group+1;
run;
data want;
length want $ 200;
 do i=1 by 1 until(last.group);
  set have;
  by group;
  want=catx('-',want,drug);
 end;
if i ne 1 then output;
keep want;
run;


&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Dec 2016 11:53:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/dealing-with-time-periods-with-start-and-end-date-and-overlap/m-p/316225#M61709</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-12-02T11:53:00Z</dc:date>
    </item>
    <item>
      <title>Re: dealing with time periods with start and end date and overlap</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/dealing-with-time-periods-with-start-and-end-date-and-overlap/m-p/316261#M61710</link>
      <description>&lt;P&gt;Ignoring patients ids, I am just trying to get aggregate numbers over a large data. I want to know the total number of prescriptions that overlap for 30 days or more.&amp;nbsp;&lt;/P&gt;&lt;P&gt;If two medications overlap, then 2&amp;nbsp;&lt;/P&gt;&lt;P&gt;if three medications overlap 3.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output above shows the classes that overlaped. so for 2 a-b and so on&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Dec 2016 14:44:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/dealing-with-time-periods-with-start-and-end-date-and-overlap/m-p/316261#M61710</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2016-12-02T14:44:00Z</dc:date>
    </item>
    <item>
      <title>Re: dealing with time periods with start and end date and overlap</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/dealing-with-time-periods-with-start-and-end-date-and-overlap/m-p/316268#M61711</link>
      <description>&lt;P&gt;KSHARP&amp;nbsp;thank you! your code works perfect for the small dataset that has multiple medications for the same patient. Can one adjust the code if you have multiple ids? How can one modify the code if you have something like this with the first column be pt id?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;1 a        01/01/2001    02/15/2001
1 b        01/02/2001    02/10/2001
1 c        04/05/2002     06/07/2002
1 d        04/15/2002     07/01/2002
1 e       04/01/2002      07/18/2002
1 f       04/05/2002      06/01/2002&lt;/PRE&gt;&lt;PRE&gt;2 a        01/01/2001    02/15/2001
2 b        01/02/2001    02/10/2001
2 c        04/05/2002     06/07/2002
2 d        04/15/2002     07/01/2002
2 e       04/01/2002      07/18/2002
2 f       04/05/2002      06/01/2002&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Dec 2016 15:01:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/dealing-with-time-periods-with-start-and-end-date-and-overlap/m-p/316268#M61711</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2016-12-02T15:01:20Z</dc:date>
    </item>
    <item>
      <title>Re: dealing with time periods with start and end date and overlap</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/dealing-with-time-periods-with-start-and-end-date-and-overlap/m-p/316438#M61719</link>
      <description>&lt;P&gt;Perhaps something like this if you want the groups within id, which makes more sense than across id.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   input id drug  $ start : mmddyy10.    end : mmddyy10.;
   format start end mmddyy10.;
cards;
1 a        01/01/2001    02/15/2001
1 b        01/02/2001    02/10/2001
1 c        04/05/2002     06/07/2002
1 d        04/15/2002     07/01/2002
1 e       04/01/2002      07/18/2002
1 f       04/05/2002      06/01/2002
2 a        01/01/2002    02/15/2002
2 b        01/05/2002    03/19/2002
2 c        01/24/2002     02/17/2002
2 d        04/10/2002     07/01/2002
2 e       04/01/2002      07/28/2002
2 f       04/25/2002      06/30/2002
;
run;

data temp;
   set have;
   by id;
   dif=lag(end)-start;

   if first.id then do;
      group=.;
      dif =.;
   end;
   if dif lt 30 then group+1;
run;

data want;
   length want $ 200;
   do i=1 by 1 until(last.group);
      set Temp;
      by id group;
      want=catx('-',want,drug);
   end;
   if i ne 1 then output;
   keep id want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I changed some date values for id=2 so that the results differed between Id. You need to decide if the rules have been applied correctly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your main data isn't sorted by ID and start date it should be before doing the step that creates temp.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Dec 2016 23:47:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/dealing-with-time-periods-with-start-and-end-date-and-overlap/m-p/316438#M61719</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-12-02T23:47:30Z</dc:date>
    </item>
    <item>
      <title>Re: dealing with time periods with start and end date and overlap</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/dealing-with-time-periods-with-start-and-end-date-and-overlap/m-p/316468#M61722</link>
      <description>&lt;PRE&gt;
Yeah. Try @ballardw 's code , or this one:


data have;
   input id drug  $ start : mmddyy10.    end : mmddyy10.;
   format start end mmddyy10.;
cards;
1 a        01/01/2001    02/15/2001
1 b        01/02/2001    02/10/2001
1 c        04/05/2002     06/07/2002
1 d        04/15/2002     07/01/2002
1 e       04/01/2002      07/18/2002
1 f       04/05/2002      06/01/2002
2 a        01/01/2002    02/15/2002
2 b        01/05/2002    03/19/2002
2 c        01/24/2002     02/17/2002
2 d        04/10/2002     07/01/2002
2 e       04/01/2002      07/28/2002
2 f       04/25/2002      06/30/2002
;
run;

data temp;
   set have;
   by id;
   dif=lag(end)-start;
   if dif lt 30 or first.id then group+1;
run;

data want;
   length want $ 200;
   do i=1 by 1 until(last.group);
      set Temp;
      by id group;
      want=catx('-',want,drug);
   end;
   if i ne 1 then output;
   keep id want;
run;

&lt;/PRE&gt;</description>
      <pubDate>Sat, 03 Dec 2016 08:17:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/dealing-with-time-periods-with-start-and-end-date-and-overlap/m-p/316468#M61722</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-12-03T08:17:23Z</dc:date>
    </item>
    <item>
      <title>Re: dealing with time periods with start and end date and overlap</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/dealing-with-time-periods-with-start-and-end-date-and-overlap/m-p/316495#M61729</link>
      <description>&lt;P&gt;Super! Thank you&amp;nbsp;&lt;SPAN class="login-bold"&gt;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884" target="_self"&gt;ballardw&amp;nbsp;&lt;/A&gt;and ksharp!&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Dec 2016 16:28:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/dealing-with-time-periods-with-start-and-end-date-and-overlap/m-p/316495#M61729</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2016-12-03T16:28:17Z</dc:date>
    </item>
    <item>
      <title>Re: dealing with time periods with start and end date and overlap</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/dealing-with-time-periods-with-start-and-end-date-and-overlap/m-p/316496#M61730</link>
      <description>&lt;P&gt;I have one more questions.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lets assume the output for id is the following:&lt;/P&gt;&lt;P&gt;1 a-b&lt;/P&gt;&lt;P&gt;1 a-b-c&lt;/P&gt;&lt;P&gt;1 a-b-c-d&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 a-b-c-e&lt;/P&gt;&lt;P&gt;2 a-b&lt;/P&gt;&lt;P&gt;2-c-d&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I create table the keeps only the highest combination for each id. I mean here we have a combintion of two drugs, three drugs, and four drugs.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a table that tell me the highest combination for patient 1 was 4 and for patient 2 is 2 and so on. Here is the output&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp;4&lt;/P&gt;&lt;P&gt;2 2&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Dec 2016 16:36:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/dealing-with-time-periods-with-start-and-end-date-and-overlap/m-p/316496#M61730</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2016-12-03T16:36:44Z</dc:date>
    </item>
    <item>
      <title>Re: dealing with time periods with start and end date and overlap</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/dealing-with-time-periods-with-start-and-end-date-and-overlap/m-p/316541#M61731</link>
      <description>&lt;PRE&gt;
data x;
input a b $20.;
cards;
1 a-b
1 a-b-c
1 a-b-c-d 
1 a-b-c-e
2 a-b
2 c-d 
;
run;
proc sql;
select a,max(countc(b,'-'))+1 as max
 from x
  group by a;
quit;

&lt;/PRE&gt;</description>
      <pubDate>Sun, 04 Dec 2016 02:47:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/dealing-with-time-periods-with-start-and-end-date-and-overlap/m-p/316541#M61731</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-12-04T02:47:28Z</dc:date>
    </item>
    <item>
      <title>Re: dealing with time periods with start and end date and overlap</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/dealing-with-time-periods-with-start-and-end-date-and-overlap/m-p/316556#M61732</link>
      <description>&lt;P&gt;Thank you ksharp, I just realized that the output of the first code is incorrect . The 30 days overlap should be 30 days or more and should his card&amp;nbsp;drugs that overlap in less than 30 days. For example, for the entries below, the code should not retain any drugs for this patient because there is no overlap of 30 days or more between the different drugs.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;1 c        04/05/2002     06/07/2002
1 d        04/15/2002     04/25/2002
1 e       04/15/2002      04/18/2002&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 04 Dec 2016 10:57:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/dealing-with-time-periods-with-start-and-end-date-and-overlap/m-p/316556#M61732</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2016-12-04T10:57:41Z</dc:date>
    </item>
    <item>
      <title>Re: dealing with time periods with start and end date and overlap</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/dealing-with-time-periods-with-start-and-end-date-and-overlap/m-p/316650#M61733</link>
      <description>&lt;PRE&gt;
OK. So you also care about END-START ?




data have;
   input id drug  $ start : mmddyy10.    end : mmddyy10.;
   format start end mmddyy10.;
cards;
1 c        04/05/2002     06/07/2002
1 d        04/15/2002     04/25/2002
1 e       04/15/2002      04/18/2002
2 a        01/01/2002    02/15/2002
2 b        01/05/2002    03/19/2002
2 c        01/24/2002     02/17/2002
2 d        04/10/2002     07/01/2002
2 e       04/01/2002      07/28/2002
2 f       04/25/2002      06/30/2002
;
run;

data temp;
   set have;
   by id;
   dif=lag(end)-start;
   if dif lt 30 or (end-start) lt 30 or first.id then group+1;
run;

data want;
   length want $ 200;
   do i=1 by 1 until(last.group);
      set Temp;
      by id group;
      want=catx('-',want,drug);
   end;
   if i ne 1 then output;
   keep id want;
run;

&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 Dec 2016 10:10:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/dealing-with-time-periods-with-start-and-end-date-and-overlap/m-p/316650#M61733</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-12-05T10:10:15Z</dc:date>
    </item>
    <item>
      <title>Re: dealing with time periods with start and end date and overlap</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/dealing-with-time-periods-with-start-and-end-date-and-overlap/m-p/316695#M61736</link>
      <description>&lt;P&gt;Thank you so much Ksharp!!&amp;nbsp;five starts!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2016 13:38:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/dealing-with-time-periods-with-start-and-end-date-and-overlap/m-p/316695#M61736</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2016-12-05T13:38:14Z</dc:date>
    </item>
    <item>
      <title>Re: dealing with time periods with start and end date and overlap</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/dealing-with-time-periods-with-start-and-end-date-and-overlap/m-p/316768#M61743</link>
      <description>&lt;P&gt;one more question, after the first code, how can I exclude drugs that overlap for the same drug. For example if I have the following outpit:&lt;/P&gt;&lt;P&gt;a-b-c-a, I want to drop the duplicate a and keep it as a-b-c&lt;/P&gt;&lt;P&gt;the same for a-a, I dont want to count the overlap if it is the same drug . Thank you again for all the help!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2016 16:38:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/dealing-with-time-periods-with-start-and-end-date-and-overlap/m-p/316768#M61743</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2016-12-05T16:38:19Z</dc:date>
    </item>
    <item>
      <title>Re: dealing with time periods with start and end date and overlap</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/dealing-with-time-periods-with-start-and-end-date-and-overlap/m-p/316919#M61751</link>
      <description>&lt;PRE&gt;
No problem.




data have;
   input id drug  $ start : mmddyy10.    end : mmddyy10.;
   format start end mmddyy10.;
cards;
1 c        04/05/2002     06/07/2002
1 d        04/15/2002     04/25/2002
1 e       04/15/2002      04/18/2002
2 a        01/01/2002    02/15/2002
2 b        01/05/2002    03/19/2002
2 c        01/24/2002     02/17/2002
2 d        04/10/2002     07/01/2002
2 e       04/01/2002      07/28/2002
2 f       04/25/2002      06/30/2002
2 f       04/25/2002      07/30/2002
;
run;

data temp;
   set have;
   by id;
   dif=lag(end)-start;
   if dif lt 30 or (end-start) lt 30 or first.id then group+1;
run;

data want;
array x{99999} $ 100 _TEMPORARY_;
n=0;
call missing(of x{*});
length want $ 200;

   do i=1 by 1 until(last.group);
      set Temp;
      by id group;
      if drug not in x then do;
       n+1;x{n}=drug;
       want=catx('-',want,drug);
      end;
   end;
   if i ne 1 then output;
   keep id want;
run;

&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Dec 2016 03:23:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/dealing-with-time-periods-with-start-and-end-date-and-overlap/m-p/316919#M61751</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-12-06T03:23:06Z</dc:date>
    </item>
    <item>
      <title>Re: dealing with time periods with start and end date and overlap</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/dealing-with-time-periods-with-start-and-end-date-and-overlap/m-p/317027#M61753</link>
      <description>&lt;P&gt;Thank you ksharp!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Dec 2016 14:19:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/dealing-with-time-periods-with-start-and-end-date-and-overlap/m-p/317027#M61753</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2016-12-06T14:19:46Z</dc:date>
    </item>
  </channel>
</rss>

