<?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: conditional overlap of two periods in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/conditional-overlap-of-two-periods/m-p/369503#M88224</link>
    <description>&lt;P&gt;Thank you&amp;nbsp;&lt;SPAN class="UserName lia-user-name lia-user-rank-Esteemed-Advisor"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="login-bold"&gt;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562" target="_self"&gt;KurtBremser&lt;/A&gt;, that is very helpful but can you provide a brief example on how to use it to account for the number of days? Thank you!&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 22 Jun 2017 14:19:27 GMT</pubDate>
    <dc:creator>lillymaginta</dc:creator>
    <dc:date>2017-06-22T14:19:27Z</dc:date>
    <item>
      <title>conditional overlap of two periods</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-overlap-of-two-periods/m-p/369440#M88199</link>
      <description>&lt;P&gt;&amp;nbsp;I have the following dataset, I need to count each id only once based on the highest order achieved into:&lt;/P&gt;&lt;P&gt;mono&lt;/P&gt;&lt;P&gt;dual&lt;/P&gt;&lt;P&gt;2 or more&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(for example: if the same patient have drugs with no overlap, another two drugs overlapped= then count this patient one time under 2 drug overlap or dual) based on the presence of one of the two conditions:&lt;/P&gt;&lt;P&gt;overlap of 60 days or more between drugs or if the drugs overlap at two different time periods by 30 days then count them (for example one period they same two drugs overlap by 30 and in another period by 40 days count this id as dual)&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;id drug  start end
1  a    1/1/2004  4/4/2004
1 b     2/2/2004   6/6/2004
1 d    1/4/2005  4/4/2005
2  a    3/1/2006    4/2/2006
2  b    2/2/2006     5/3/2006
2  c    2/2/2006      4/4/2006
2  d   2/3/2001       4/4/2001
3  a    3/3/2001      4/3/2001
3  b    3/2/2002      4/2/2002
4  a    6/1/2001      8/2/2001
4  b    6/1/2001       7/7/2001
4  a    2/2/2001       4/4/2001
4  b    2/5/2001       3/28/2001&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;the output would be&amp;nbsp;&lt;/P&gt;&lt;P&gt;mono or one drug : 1 (patient 3 counted here)&lt;/P&gt;&lt;P&gt;dual &amp;nbsp;or two drugs overlap : 2 (patient 2 and 4 would be counted here)&lt;/P&gt;&lt;P&gt;three or more (patient 1)&lt;/P&gt;&lt;P&gt;I don't need the actual drugs that overlap just a count of the frequency where each patient can be counted once only.&lt;/P&gt;&lt;P&gt;There are a totol of 6 drugs.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 11:50:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-overlap-of-two-periods/m-p/369440#M88199</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2017-06-22T11:50:22Z</dc:date>
    </item>
    <item>
      <title>Re: conditional overlap of two periods</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-overlap-of-two-periods/m-p/369442#M88200</link>
      <description>&lt;P&gt;I don't have time right now to code anything, but a couple of pointers. &amp;nbsp;You can retain an overlap counter by id, increment it based on your logic and start_date between lag(start_date) and lag(end_date). &amp;nbsp;Then output only last.id. &amp;nbsp;This would give you a list of ids and a count of overlaps which you could then count.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 11:57:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-overlap-of-two-periods/m-p/369442#M88200</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-06-22T11:57:16Z</dc:date>
    </item>
    <item>
      <title>Re: conditional overlap of two periods</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-overlap-of-two-periods/m-p/369454#M88205</link>
      <description>&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    1/1/2004  4/4/2004
1 b     2/2/2004   6/6/2004
1 d    1/4/2005  4/4/2005
2  a    3/1/2006    4/2/2006
2  b    2/2/2006     5/3/2006
2  c    2/2/2006      4/4/2006
2  d   2/3/2001       4/4/2001
3  a    3/3/2001      4/3/2001
3  b    3/2/2002      4/2/2002
4  a    6/1/2001      8/2/2001
4  b    6/1/2001       7/7/2001
4  a    2/2/2001       4/4/2001
4  b    2/5/2001       3/28/2001
;
run;

data want1;
set have;
by id;
drugno = 1;
retain count;
if first.id then count = 1; else count + 1;
if lag(end) &amp;gt;= start and count &amp;gt; 1 then drugno = drugno + 1;
if lag2(end) &amp;gt;= start and count &amp;gt; 2 then drugno = drugno + 1;
drugno = min(drugno,3);
run;

proc sql;
create table want2 as select id, max(drugno) as drugno
from want1 group by id;
quit;

proc freq data=want2;
tables drugno;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This detects simple overlaps. If you want the length of the overlaps factored in, you will have to create several drugcounts for different lengths and drugs, so you can then make your further calculations. This is just to show the use of the lag() functions.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 12:25:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-overlap-of-two-periods/m-p/369454#M88205</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-06-22T12:25:03Z</dc:date>
    </item>
    <item>
      <title>Re: conditional overlap of two periods</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-overlap-of-two-periods/m-p/369503#M88224</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;SPAN class="UserName lia-user-name lia-user-rank-Esteemed-Advisor"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="login-bold"&gt;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562" target="_self"&gt;KurtBremser&lt;/A&gt;, that is very helpful but can you provide a brief example on how to use it to account for the number of days? Thank you!&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 14:19:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-overlap-of-two-periods/m-p/369503#M88224</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2017-06-22T14:19:27Z</dc:date>
    </item>
  </channel>
</rss>

