<?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: Overlapping drugs in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Overlapping-drugs/m-p/927977#M365127</link>
    <description>&lt;P&gt;So you don't take into account of variable&amp;nbsp;ENROLID ?&lt;/P&gt;</description>
    <pubDate>Sat, 11 May 2024 06:33:14 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2024-05-11T06:33:14Z</dc:date>
    <item>
      <title>Overlapping drugs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overlapping-drugs/m-p/927952#M365119</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;Please help me to code this. This is the dataset below-&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2024-05-10 at 15.25.59.png" style="width: 712px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96440i04283020CE4024F8/image-dimensions/712x122?v=v2" width="712" height="122" role="button" title="Screen Shot 2024-05-10 at 15.25.59.png" alt="Screen Shot 2024-05-10 at 15.25.59.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt; I have 2 drugs being used for each ID i.e., SGA and DM. I have multiple start date and end dates for each ID and drug. I want to see if the DM_start falls into any of the SGA_start and SGA_end under each id. That is DM_start of period 3 can fall in the SGA_start and SGA_end of period1.&lt;/P&gt;
&lt;P&gt;And also calculate the number of overlapping days for each time period. I want to know the no. of days for each orange period.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2024-05-10 at 15.40.54.png" style="width: 698px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96441i884A33231E92FF16/image-dimensions/698x220?v=v2" width="698" height="220" role="button" title="Screen Shot 2024-05-10 at 15.40.54.png" alt="Screen Shot 2024-05-10 at 15.40.54.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Thank you all in advance,&lt;/P&gt;
&lt;P&gt;Any help would be appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2024 20:44:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overlapping-drugs/m-p/927952#M365119</guid>
      <dc:creator>stellapersis7</dc:creator>
      <dc:date>2024-05-10T20:44:53Z</dc:date>
    </item>
    <item>
      <title>Re: Overlapping drugs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overlapping-drugs/m-p/927954#M365120</link>
      <description>&lt;P&gt;You need to describe what that picture means a lot better. For example, your first three observations have the exact same SGA start and end for period values of 1, 2 and 3. I have hard time understanding just that bit at all.&lt;/P&gt;
&lt;P&gt;All of the SGA start/end pairs shown as examples are start and end on the same day so your picture of 'overlap' doesn't seem to apply to any SGA values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want help with real code then you need to provide something we can code with.&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the &amp;lt;/&amp;gt; icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This does not have to be actual data but should behave in similar manner.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, if this picture is from a set you built from different sources it may not be structured well to analyze as you want and perhaps examples of the sets before this was build is more appropriate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2024 21:21:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overlapping-drugs/m-p/927954#M365120</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-05-10T21:21:39Z</dc:date>
    </item>
    <item>
      <title>Re: Overlapping drugs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overlapping-drugs/m-p/927960#M365122</link>
      <description>&lt;P&gt;Thank you for the reply.&lt;/P&gt;
&lt;P&gt;Yes, in the picture SGA_start and end is just one for those ID, but there are different IDs which have a different SGA _start and end.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I want to check each DM_start date-- if it falls between each of the SGA_start and SGA_end date of that observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data WORK.DM_SGA1;&lt;BR /&gt;infile datalines dsd truncover;&lt;BR /&gt;input ENROLID:32. SVCDATE:MMDDYY10. INDEX_SGA:MMDDYY10. SGA_START:MMDDYY10. SGA_END:MMDDYY10. INDEX_DM:MMDDYY10. DM_START:MMDDYY10. DM_END:MMDDYY10.;&lt;BR /&gt;format SVCDATE MMDDYY10. INDEX_SGA MMDDYY10. SGA_START MMDDYY10. SGA_END MMDDYY10. INDEX_DM MMDDYY10. DM_START MMDDYY10. DM_END MMDDYY10.;&lt;BR /&gt;label ENROLID="Enrollee ID" SVCDATE="Date Service Incurred";&lt;BR /&gt;datalines;&lt;BR /&gt;27264303 07/18/2017 01/15/2017 05/27/2019 05/27/2019 02/20/2017 07/18/2017 07/18/2017&lt;BR /&gt;27264303 11/03/2018 01/15/2017 05/27/2019 05/27/2019 02/20/2017 11/03/2018 11/03/2018&lt;BR /&gt;27264303 05/06/2019 01/15/2017 05/27/2019 05/27/2019 02/20/2017 05/06/2019 05/06/2019&lt;BR /&gt;28584803 03/07/2017 03/07/2017 12/09/2019 12/09/2019 03/07/2017 03/07/2017 03/07/2017&lt;BR /&gt;28584803 08/28/2019 03/07/2017 12/09/2019 12/09/2019 03/07/2017 08/28/2019 08/28/2019&lt;BR /&gt;28584803 11/26/2019 03/07/2017 12/09/2019 12/09/2019 03/07/2017 11/26/2019 11/26/2019&lt;BR /&gt;93277105 05/08/2018 01/16/2017 05/23/2017 05/23/2017 02/06/2018 05/08/2018 05/08/2018&lt;BR /&gt;93277105 11/05/2018 01/16/2017 01/07/2018 01/07/2018 02/06/2018 11/05/2018 11/05/2018&lt;BR /&gt;93277105 01/11/2019 01/16/2017 05/01/2018 05/01/2018 02/06/2018 01/11/2019 01/11/2019&lt;BR /&gt;93277105 09/29/2019 01/16/2017 07/27/2018 07/27/2018 02/06/2018 09/29/2019 09/29/2019&lt;BR /&gt;93277105 12/16/2019 01/16/2017 09/28/2018 09/28/2018 02/06/2018 12/16/2019 12/16/2019&lt;BR /&gt;93277105 12/19/2018 01/16/2017 12/19/2018 12/19/2018 02/06/2018 12/16/2019 12/16/2019&lt;BR /&gt;93277105 08/04/2019 01/16/2017 08/04/2019 08/04/2019 02/06/2018 12/16/2019 12/16/2019&lt;BR /&gt;93277105 12/18/2019 01/16/2017 12/18/2019 12/18/2019 02/06/2018 12/16/2019 12/16/2019&lt;BR /&gt;97434102 12/06/2017 09/05/2017 12/27/2017 12/27/2017 09/05/2017 12/06/2017 12/06/2017&lt;BR /&gt;;;;;&lt;/P&gt;</description>
      <pubDate>Sat, 11 May 2024 02:03:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overlapping-drugs/m-p/927960#M365122</guid>
      <dc:creator>stellapersis7</dc:creator>
      <dc:date>2024-05-11T02:03:13Z</dc:date>
    </item>
    <item>
      <title>Re: Overlapping drugs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overlapping-drugs/m-p/927972#M365126</link>
      <description>&lt;P&gt;The sample data you've posted needs rework to define periods &amp;gt;0 and cases with overlaps.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1715400910743.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96445i81CD83124B3CE0A0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1715400910743.png" alt="Patrick_0-1715400910743.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you created useful sample data you could try if below code gets you closer to what you want.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.have;
  infile datalines dsd dlm=' ' truncover;
  input ENROLID:32. SVCDATE:MMDDYY10. INDEX_SGA:MMDDYY10. SGA_START:MMDDYY10. SGA_END:MMDDYY10. INDEX_DM:MMDDYY10. DM_START:MMDDYY10. DM_END:MMDDYY10.;
  format SVCDATE INDEX_SGA SGA_START SGA_END INDEX_DM DM_START DM_END date9.;
  label ENROLID="Enrollee ID" SVCDATE="Date Service Incurred";
  datalines4;
27264303 07/18/2017 01/15/2017 05/27/2019 05/27/2019 02/20/2017 07/18/2017 07/18/2017
27264303 11/03/2018 01/15/2017 05/27/2019 05/27/2019 02/20/2017 11/03/2018 11/03/2018
27264303 05/06/2019 01/15/2017 05/27/2019 05/27/2019 02/20/2017 05/06/2019 05/06/2019
28584803 03/07/2017 03/07/2017 12/09/2019 12/09/2019 03/07/2017 03/07/2017 03/07/2017
28584803 08/28/2019 03/07/2017 12/09/2019 12/09/2019 03/07/2017 08/28/2019 08/28/2019
28584803 11/26/2019 03/07/2017 12/09/2019 12/09/2019 03/07/2017 11/26/2019 11/26/2019
93277105 05/08/2018 01/16/2017 05/23/2017 05/23/2017 02/06/2018 05/08/2018 05/08/2018
93277105 11/05/2018 01/16/2017 01/07/2018 01/07/2018 02/06/2018 11/05/2018 11/05/2018
93277105 01/11/2019 01/16/2017 05/01/2018 05/01/2018 02/06/2018 01/11/2019 01/11/2019
93277105 09/29/2019 01/16/2017 07/27/2018 07/27/2018 02/06/2018 09/29/2019 09/29/2019
93277105 12/16/2019 01/16/2017 09/28/2018 09/28/2018 02/06/2018 12/16/2019 12/16/2019
93277105 12/19/2018 01/16/2017 12/19/2018 12/19/2018 02/06/2018 12/16/2019 12/16/2019
93277105 08/04/2019 01/16/2017 08/04/2019 08/04/2019 02/06/2018 12/16/2019 12/16/2019
93277105 12/18/2019 01/16/2017 12/18/2019 12/18/2019 02/06/2018 12/16/2019 12/16/2019
97434102 12/06/2017 09/05/2017 12/27/2017 12/27/2017 09/05/2017 12/06/2017 12/06/2017
;;;;

data work.prep;
  length row_id 8;
  set work.prep;
  row_id+1;
  keep row_id ENROLID sga_: dm_:;
run;

proc sql feedback;
/*  create table want as*/
  select 
    l.*
    ,case 
      when nmiss(l.SGA_END,r.DM_END,l.SGA_START,r.DM_START)=0 then 
        min(l.SGA_END,r.DM_END) - max(l.SGA_START,r.DM_START)
      else 0
      end as overlap_days
/*    ,l.SGA_START as l_sga_start format=date9.*/
/*    ,l.SGA_END as l_sga_end format=date9.*/
/*    ,r.SGA_START as r_sga_start format=date9.*/
/*    ,r.SGA_END as r_sga_end format=date9.*/
/*    ,l.row_id as l_row_id*/
/*    ,r.row_id as r_row_id*/
  from work.prep l

  left join work.prep r
    on 
      l.ENROLID=r.ENROLID
      and min(l.SGA_END,r.DM_END) - max(l.SGA_START,r.DM_START)&amp;gt;0
      and l.row_id&amp;lt;=r.row_id

  order by l.row_id
  ;

quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please note that in principle a DM period could overlap with multiple SGA periods (defined in multiple rows). Above code will return one row per overlap (or just the source row if no overlap).&lt;/P&gt;
&lt;P&gt;If you prefer to store this data in a single row within multiple variables then you would need to transpose the result back to a single row by row_id.&lt;/P&gt;</description>
      <pubDate>Sat, 11 May 2024 04:25:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overlapping-drugs/m-p/927972#M365126</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-05-11T04:25:39Z</dc:date>
    </item>
    <item>
      <title>Re: Overlapping drugs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overlapping-drugs/m-p/927977#M365127</link>
      <description>&lt;P&gt;So you don't take into account of variable&amp;nbsp;ENROLID ?&lt;/P&gt;</description>
      <pubDate>Sat, 11 May 2024 06:33:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overlapping-drugs/m-p/927977#M365127</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-05-11T06:33:14Z</dc:date>
    </item>
    <item>
      <title>Re: Overlapping drugs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overlapping-drugs/m-p/927986#M365130</link>
      <description>&lt;P&gt;I already defined periods as having gaps &amp;gt;60 days for both SGA and DM. So the screen shot I am showing is after taking the gaps of &amp;gt;60 days into account and I need to do cases with overlap &amp;gt;30 days.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I did the identification of fill dates and gaps of 60 days for drug SGA in a dataset X and the same DM in a dataset Y and merged both. The result is the dataset screenshot which I posted.&lt;/P&gt;
&lt;P&gt;However,&amp;nbsp;The above code did not work. As I see the dataset., there are overlaps but it has given me zero overlaps for all observations. Is there another way to do it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 May 2024 13:46:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overlapping-drugs/m-p/927986#M365130</guid>
      <dc:creator>stellapersis7</dc:creator>
      <dc:date>2024-05-11T13:46:17Z</dc:date>
    </item>
    <item>
      <title>Re: Overlapping drugs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overlapping-drugs/m-p/928007#M365144</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;As I see the dataset., there are overlaps but it has given me zero overlaps for all observations. Is there another way to do it?&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;If above statement is related to the code sample I shared earlier: &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The overlaps are all zero because it uses the data you shared via data step and there start and end dates have always the same date and though there aren't any overlaps. You can amend your sample data (data have; step) so they contain overlapping periods and then test again if the script now returns the overlaps you're after.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Is there another way to do it?&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;If you are after some sample code then you need to &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1) provide sample data via data step (Have) , &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;2) show the desired result based on the sample data (Want), &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;3) explain the logic required to get from have to want.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 11 May 2024 23:49:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overlapping-drugs/m-p/928007#M365144</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-05-11T23:49:55Z</dc:date>
    </item>
    <item>
      <title>Re: Overlapping drugs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overlapping-drugs/m-p/928013#M365147</link>
      <description>&lt;P&gt;Thanks for your help.&lt;/P&gt;
&lt;P&gt;Going a step back to see if I did it correctly...So, I have 2 datasets- one with drug sga with their start and end dates (SGA_Start and SGA_end) I have imposed the criteria of maximum gap of 60 days and got these multiple start and end dates for each ID.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data WORK.SGA_INDEX5;&lt;BR /&gt;infile datalines dsd truncover;&lt;BR /&gt;input ENROLID:32. INDEX_SGA:MMDDYY10. PERIOD_SGA:32. SGA_START:MMDDYY10. SGA_END:MMDDYY10.;&lt;BR /&gt;format INDEX_SGA MMDDYY10. SGA_START MMDDYY10. SGA_END MMDDYY10.;&lt;BR /&gt;label ENROLID="Enrollee ID";&lt;BR /&gt;datalines;&lt;/P&gt;
&lt;P&gt;13442404 02/12/2018 1 02/12/2018 02/12/2018&lt;BR /&gt;13442404 02/12/2018 2 08/01/2019 08/01/2019&lt;BR /&gt;13442404 02/12/2018 3 11/07/2019 11/07/2019&lt;BR /&gt;13764305 02/07/2018 1 02/07/2018 02/07/2018&lt;BR /&gt;13764305 02/07/2018 2 05/10/2018 05/10/2018&lt;BR /&gt;13764305 02/07/2018 3 08/04/2018 08/04/2018&lt;BR /&gt;13764305 02/07/2018 4 11/08/2018 11/08/2018&lt;BR /&gt;13764305 02/07/2018 5 02/14/2019 02/14/2019&lt;BR /&gt;13764305 02/07/2018 6 05/15/2019 05/15/2019&lt;BR /&gt;13764305 02/07/2018 7 08/13/2019 08/13/2019&lt;BR /&gt;13764305 02/07/2018 8 11/14/2019 11/14/2019&lt;BR /&gt;14105204 02/17/2018 1 09/19/2018 09/19/2018&lt;BR /&gt;14105204 02/17/2018 2 01/21/2019 01/21/2019&lt;BR /&gt;14958903 01/23/2018 1 07/15/2018 07/15/2018&lt;BR /&gt;14958903 01/23/2018 2 10/09/2018 10/09/2018&lt;BR /&gt;14958903 01/23/2018 3 12/11/2019 12/11/2019&lt;BR /&gt;15715903 06/04/2018 1 06/04/2018 06/04/2018&lt;BR /&gt;15818504 10/02/2019 2 12/13/2019 12/13/2019&lt;BR /&gt;26990304 02/11/2017 1 12/30/2019 12/30/2019&lt;BR /&gt;27174506 01/13/2017 1 06/11/2018 06/11/2018&lt;BR /&gt;27193504 06/20/2017 1 06/20/2017 06/20/2017&lt;BR /&gt;27193504 06/20/2017 2 08/27/2017 08/27/2017&lt;BR /&gt;27193504 06/20/2017 3 12/30/2019 12/30/2019&lt;BR /&gt;27264303 01/15/2017 1 05/27/2019 05/27/2019&lt;BR /&gt;27274805 05/25/2017 1 06/09/2017 06/09/2017&lt;BR /&gt;;;;;&lt;/P&gt;
&lt;P&gt;And the second dataset is the drug DM with their start and end dates (DM_Start and DM_END). I have used the same criteria of maximum of 60 days gap and got these multiple start and end dates of these drug.&lt;/P&gt;
&lt;P&gt;data WORK.DM_INDEX5;&lt;BR /&gt;infile datalines dsd truncover;&lt;BR /&gt;input ENROLID:32. INDEX_DM:MMDDYY10. PERIOD_dm:32. DM_START:MMDDYY10. DM_END:MMDDYY10.;&lt;BR /&gt;format INDEX_DM MMDDYY10. DM_START MMDDYY10. DM_END MMDDYY10.;&lt;BR /&gt;label ENROLID="Enrollee ID";&lt;BR /&gt;datalines;&lt;BR /&gt;27264303 02/20/2017 1 07/18/2017 07/18/2017&lt;BR /&gt;27264303 02/20/2017 2 11/03/2018 11/03/2018&lt;BR /&gt;27264303 02/20/2017 3 05/06/2019 05/06/2019&lt;BR /&gt;28584803 03/07/2017 1 03/07/2017 03/07/2017&lt;BR /&gt;28584803 03/07/2017 2 08/28/2019 08/28/2019&lt;BR /&gt;28584803 03/07/2017 3 11/26/2019 11/26/2019&lt;BR /&gt;33471402 07/17/2019 1 12/20/2019 12/20/2019&lt;BR /&gt;93277105 02/06/2018 1 05/08/2018 05/08/2018&lt;BR /&gt;93277105 02/06/2018 2 11/05/2018 11/05/2018&lt;BR /&gt;93277105 02/06/2018 3 01/11/2019 01/11/2019&lt;BR /&gt;93277105 02/06/2018 4 09/29/2019 09/29/2019&lt;BR /&gt;93277105 02/06/2018 5 12/16/2019 12/16/2019&lt;BR /&gt;97434102 09/05/2017 1 12/06/2017 12/06/2017&lt;BR /&gt;99153403 01/16/2017 1 02/21/2017 02/21/2017&lt;BR /&gt;99153403 01/16/2017 2 07/24/2017 07/24/2017&lt;BR /&gt;100012102 08/08/2017 1 08/08/2017 08/08/2017&lt;BR /&gt;100012102 08/08/2017 2 11/14/2017 11/14/2017&lt;BR /&gt;100274803 01/16/2017 1 01/16/2017 01/16/2017&lt;BR /&gt;100303908 03/19/2017 2 03/19/2017 03/19/2017&lt;BR /&gt;100303908 03/19/2017 3 12/04/2017 12/04/2017&lt;BR /&gt;101032604 03/30/2017 1 04/28/2017 04/28/2017&lt;BR /&gt;101032604 03/30/2017 2 08/30/2017 08/30/2017&lt;BR /&gt;101032604 03/30/2017 3 11/25/2017 11/25/2017&lt;BR /&gt;102580704 01/12/2017 1 04/26/2017 04/26/2017&lt;BR /&gt;102580704 01/12/2017 2 09/15/2017 09/15/2017&lt;BR /&gt;;;;;&lt;/P&gt;
&lt;P&gt;I am looking for the all the durations between dm_start and dm_end dates which fall between any of the sga_start and sga_end.&lt;/P&gt;
&lt;TABLE border="0" width="435" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL span="5" width="87" /&gt;&lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD colspan="4" width="348" height="21" class="xl66"&gt;data I have&lt;/TD&gt;
&lt;TD width="87"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="21"&gt;id&lt;/TD&gt;
&lt;TD&gt;sga_start&lt;/TD&gt;
&lt;TD&gt;sga_end&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="21" align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right" class="xl65"&gt;1/1/17&lt;/TD&gt;
&lt;TD align="right" class="xl65"&gt;7/1/17&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="21" align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right" class="xl65"&gt;10/1/17&lt;/TD&gt;
&lt;TD align="right" class="xl65"&gt;12/1/17&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="21" align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right" class="xl65"&gt;2/1/17&lt;/TD&gt;
&lt;TD align="right" class="xl65"&gt;4/1/17&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="21" align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right" class="xl65"&gt;9/1/17&lt;/TD&gt;
&lt;TD align="right" class="xl65"&gt;11/1/17&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="21"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="21"&gt;id&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/TD&gt;
&lt;TD&gt;dm_start&lt;/TD&gt;
&lt;TD&gt;dm_end&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="21" align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right" class="xl65"&gt;4/1/17&lt;/TD&gt;
&lt;TD align="right" class="xl65"&gt;5/1/17&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="21" align="right"&gt;1&lt;/TD&gt;
&lt;TD align="right" class="xl65"&gt;6/1/17&lt;/TD&gt;
&lt;TD align="right" class="xl65"&gt;12/1/17&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="21" align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right" class="xl65"&gt;3/1/17&lt;/TD&gt;
&lt;TD align="right" class="xl65"&gt;4/1/17&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="21" align="right"&gt;2&lt;/TD&gt;
&lt;TD align="right" class="xl65"&gt;9/1/17&lt;/TD&gt;
&lt;TD align="right" class="xl65"&gt;12/1/17&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD colspan="5" height="21" class="xl66"&gt;data I want&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="21"&gt;id&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;start&lt;/TD&gt;
&lt;TD&gt;end&lt;/TD&gt;
&lt;TD&gt;day&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="21" align="right"&gt;1&lt;/TD&gt;
&lt;TD&gt;overlap1&lt;/TD&gt;
&lt;TD align="right" class="xl65"&gt;4/1/17&lt;/TD&gt;
&lt;TD align="right" class="xl65"&gt;5/1/17&lt;/TD&gt;
&lt;TD align="right"&gt;30&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="21"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;overlap2&lt;/TD&gt;
&lt;TD align="right" class="xl65"&gt;6/1/17&lt;/TD&gt;
&lt;TD align="right" class="xl65"&gt;7/1/17&lt;/TD&gt;
&lt;TD align="right"&gt;91&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="21"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;overlap3&lt;/TD&gt;
&lt;TD align="right" class="xl65"&gt;10/1/17&lt;/TD&gt;
&lt;TD align="right" class="xl65"&gt;12/1/17&lt;/TD&gt;
&lt;TD align="right"&gt;60&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="21" align="right"&gt;2&lt;/TD&gt;
&lt;TD&gt;overlap1&lt;/TD&gt;
&lt;TD align="right" class="xl65"&gt;3/1/17&lt;/TD&gt;
&lt;TD align="right" class="xl65"&gt;4/1/17&lt;/TD&gt;
&lt;TD align="right"&gt;30&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="21"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;overlap2&lt;/TD&gt;
&lt;TD align="right" class="xl65"&gt;9/1/17&lt;/TD&gt;
&lt;TD align="right" class="xl65"&gt;11/1/17&lt;/TD&gt;
&lt;TD align="right"&gt;61&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Sun, 12 May 2024 01:17:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overlapping-drugs/m-p/928013#M365147</guid>
      <dc:creator>stellapersis7</dc:creator>
      <dc:date>2024-05-12T01:17:12Z</dc:date>
    </item>
    <item>
      <title>Re: Overlapping drugs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overlapping-drugs/m-p/928017#M365151</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sga;
infile cards expandtabs;
input id	(sga_start	sga_end) (:mmddyy10.);
format sga_start	sga_end mmddyy10. ;
cards;
1	1/1/17	7/1/17	 	 
1	10/1/17	12/1/17	 	 
2	2/1/17	4/1/17	 	 
2	9/1/17	11/1/17	
;
data dm;
infile cards expandtabs;
input id	(dm_start	dm_end) (:mmddyy10.);
format dm_start	dm_end mmddyy10. ;
cards;
1	4/1/17	5/1/17	 	 
1	6/1/17	12/1/17	 	 
2	3/1/17	4/1/17	 	 
2	9/1/17	12/1/17
;


data SGA2;
 set sga;
 label='SGA';
 do date=SGA_START to SGA_END;
  output;
 end;
 keep  id date label;
 format date date9.;
run;
data DM2;
 set dm;
 label='DM ';
 do date=DM_START to DM_END;
  output;
 end;
 keep id date label;
 format date date9.;
run;
data temp;
 set SGA2 DM2;
run;
proc sort  data=temp nodupkey;
by id  date label;
run;
data temp2;
do until(last.date);
 set temp;
 by id date;
 length tag $ 40;
 tag=catx('|',tag,label);
end;
drop label;
run;
data temp3;
 set temp2;
 by id tag notsorted;
 if first.tag or dif(date) ne 1 then group+1;
run;
proc sql;
create table want as
select id,group,tag,min(date) as start format=mmddyy10.,max(date) as end format=mmddyy10.,count(*) as days
 from temp3
  group by id,group,tag
   having findc(tag,'|')
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 12 May 2024 02:01:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overlapping-drugs/m-p/928017#M365151</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-05-12T02:01:45Z</dc:date>
    </item>
    <item>
      <title>Re: Overlapping drugs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overlapping-drugs/m-p/928177#M365188</link>
      <description>&lt;P&gt;It worked. Thank you&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 May 2024 17:28:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overlapping-drugs/m-p/928177#M365188</guid>
      <dc:creator>stellapersis7</dc:creator>
      <dc:date>2024-05-13T17:28:48Z</dc:date>
    </item>
    <item>
      <title>Re: Overlapping drugs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overlapping-drugs/m-p/930264#M365992</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have one follow up question regarding this,&lt;/P&gt;
&lt;P&gt;I want to know the duration between "SGA_START" and "start". When I merge dataset 'want' with 'sga2', the time period is not overlapping horizontally and is not capturing all the overlap periods, Can you help me with the code.&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Thu, 30 May 2024 13:14:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overlapping-drugs/m-p/930264#M365992</guid>
      <dc:creator>stellapersis7</dc:creator>
      <dc:date>2024-05-30T13:14:53Z</dc:date>
    </item>
  </channel>
</rss>

