<?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: removing gaps between treatment dates given a condition in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/removing-gaps-between-treatment-dates-given-a-condition/m-p/761753#M30332</link>
    <description>&lt;P&gt;Why are 3rd and 4th obs combined? Between April, 16th and April, 23rd are more than five days, or have i misinterpreted your logic?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 16 Aug 2021 09:24:02 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2021-08-16T09:24:02Z</dc:date>
    <item>
      <title>removing gaps between treatment dates given a condition</title>
      <link>https://communities.sas.com/t5/New-SAS-User/removing-gaps-between-treatment-dates-given-a-condition/m-p/761735#M30329</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Hi&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;I am junior with SAS and I would love your help.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;I am dealing with a patient treatment dataset. Patients (patient) are receiving treatment (antibiotic) with a start date (start) and end dates (end) for each treatment. There are some gaps between the start and end dates but where such an interruption occurs and a patent re-starts the same antibiotic that has stopped within 5 days, this interruption should be treated as if the first treatment was continuous.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Eg have;&lt;/STRONG&gt;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="158"&gt;
&lt;P&gt;Patient&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="153"&gt;
&lt;P&gt;Antibiotic&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="145"&gt;
&lt;P&gt;start&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="145"&gt;
&lt;P&gt;End&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="158"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="153"&gt;
&lt;P&gt;cipro&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="145"&gt;
&lt;P&gt;16APR2018&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="145"&gt;
&lt;P&gt;21APR2018&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="158"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="153"&gt;
&lt;P&gt;cipro&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="145"&gt;
&lt;P&gt;23APR2018&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="145"&gt;
&lt;P&gt;29APR2018&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="158"&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="153"&gt;
&lt;P&gt;Cipro,flagyl&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="145"&gt;
&lt;P&gt;16APR2018&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="145"&gt;
&lt;P&gt;16APR2018&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="158"&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="153"&gt;
&lt;P&gt;Cipro,flagyl&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="145"&gt;
&lt;P&gt;23APR2018&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="145"&gt;
&lt;P&gt;29APR2018&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="158"&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="153"&gt;
&lt;P&gt;cipro&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="145"&gt;
&lt;P&gt;30JUN2018&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="145"&gt;
&lt;P&gt;29JUL2018&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Want&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="158"&gt;
&lt;P&gt;Patient&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="153"&gt;
&lt;P&gt;Antibiotic&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="145"&gt;
&lt;P&gt;start&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="145"&gt;
&lt;P&gt;End&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="158"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="153"&gt;
&lt;P&gt;cipro&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="145"&gt;
&lt;P&gt;16APR2018&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="145"&gt;
&lt;P&gt;29APR2018&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="158"&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="153"&gt;
&lt;P&gt;Cipro,flagyl&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="145"&gt;
&lt;P&gt;16APR2018&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="145"&gt;
&lt;P&gt;29APR2018&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="158"&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="153"&gt;
&lt;P&gt;cipro&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="145"&gt;
&lt;P&gt;30JUN2018&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="145"&gt;
&lt;P&gt;29JUL2018&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a lot&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dathan&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 06:05:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/removing-gaps-between-treatment-dates-given-a-condition/m-p/761735#M30329</guid>
      <dc:creator>DathanMD</dc:creator>
      <dc:date>2021-08-16T06:05:55Z</dc:date>
    </item>
    <item>
      <title>Re: removing gaps between treatment dates given a condition</title>
      <link>https://communities.sas.com/t5/New-SAS-User/removing-gaps-between-treatment-dates-given-a-condition/m-p/761738#M30330</link>
      <description>&lt;P&gt;Please post the data in usable form. Similar questions are quite often asked and answered, it may be faster to use one of the existing solution and adept it to your needs, than waiting for a tailor-made solution.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 06:40:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/removing-gaps-between-treatment-dates-given-a-condition/m-p/761738#M30330</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-08-16T06:40:42Z</dc:date>
    </item>
    <item>
      <title>Re: removing gaps between treatment dates given a condition</title>
      <link>https://communities.sas.com/t5/New-SAS-User/removing-gaps-between-treatment-dates-given-a-condition/m-p/761742#M30331</link>
      <description>&lt;P&gt;Thanks Andreas_lds for offering to help;&lt;/P&gt;
&lt;P&gt;Below is the data in usable form ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;length antibiotic $200;&lt;BR /&gt;input patient antibiotic $ start:date9. end:date9.;&lt;BR /&gt;format start end date9.;&lt;BR /&gt;cards;&lt;BR /&gt;1 cipro 16APR2018 21APR2018&lt;BR /&gt;1 cipro 23APR2018 29APR2018&lt;BR /&gt;2 Cipro+flagyl 16APR2018 16APR2018&lt;BR /&gt;2 Cipro+flagyl 23APR2018 29APR2018&lt;BR /&gt;2 cipro 30JUN2018 29JUL2018&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data want;&lt;BR /&gt;length antibiotic $200;&lt;BR /&gt;input patient antibiotic $ start:date9. end:date9.;&lt;BR /&gt;format start end date9.;&lt;BR /&gt;cards;&lt;BR /&gt;1 cipro 16APR2018 29APR2018&lt;BR /&gt;2 Cipro+flagyl 16APR2018 29APR2018&lt;BR /&gt;2 cipro 30JUN2018 29JUL2018&lt;/P&gt;
&lt;P&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 07:35:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/removing-gaps-between-treatment-dates-given-a-condition/m-p/761742#M30331</guid>
      <dc:creator>DathanMD</dc:creator>
      <dc:date>2021-08-16T07:35:28Z</dc:date>
    </item>
    <item>
      <title>Re: removing gaps between treatment dates given a condition</title>
      <link>https://communities.sas.com/t5/New-SAS-User/removing-gaps-between-treatment-dates-given-a-condition/m-p/761753#M30332</link>
      <description>&lt;P&gt;Why are 3rd and 4th obs combined? Between April, 16th and April, 23rd are more than five days, or have i misinterpreted your logic?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 09:24:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/removing-gaps-between-treatment-dates-given-a-condition/m-p/761753#M30332</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-08-16T09:24:02Z</dc:date>
    </item>
    <item>
      <title>Re: removing gaps between treatment dates given a condition</title>
      <link>https://communities.sas.com/t5/New-SAS-User/removing-gaps-between-treatment-dates-given-a-condition/m-p/761757#M30333</link>
      <description>&lt;P&gt;Oops my mistake! I have twicked the data "have".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;length antibiotic $200;&lt;BR /&gt;input patient antibiotic $ start:date9. end:date9.;&lt;BR /&gt;format start end date9.;&lt;BR /&gt;cards;&lt;BR /&gt;1 cipro 16APR2018 21APR2018&lt;BR /&gt;1 cipro 23APR2018 29APR2018&lt;BR /&gt;2 Cipro+flagyl 16APR2018 19APR2018&lt;BR /&gt;2 Cipro+flagyl 23APR2018 29APR2018&lt;BR /&gt;2 cipro 30JUN2018 29JUL2018&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data want;&lt;BR /&gt;length antibiotic $200;&lt;BR /&gt;input patient antibiotic $ start:date9. end:date9.;&lt;BR /&gt;format start end date9.;&lt;BR /&gt;cards;&lt;BR /&gt;1 cipro 16APR2018 29APR2018&lt;BR /&gt;2 Cipro+flagyl 16APR2018 29APR2018&lt;BR /&gt;2 cipro 30JUN2018 29JUL2018&lt;/P&gt;
&lt;P&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 09:29:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/removing-gaps-between-treatment-dates-given-a-condition/m-p/761757#M30333</guid>
      <dc:creator>DathanMD</dc:creator>
      <dc:date>2021-08-16T09:29:23Z</dc:date>
    </item>
    <item>
      <title>Re: removing gaps between treatment dates given a condition</title>
      <link>https://communities.sas.com/t5/New-SAS-User/removing-gaps-between-treatment-dates-given-a-condition/m-p/761760#M30334</link>
      <description>&lt;P&gt;This is not the most beautiful or elegant solution:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=work.have out=work.sorted;
   by Patient Antibiotic Start;
run;

data work.want;
   set work.sorted;
   by Patient Antibiotic;
   
   retain lastStart lastEnd;
   
   if first.Antibiotic then do;
      call missing(lastStart, lastEnd);
   end;
   else do;   
      if lastStart &amp;lt;= start &amp;lt;= (lastEnd + 5) then do;
         lastEnd = end;
      end;
      else do;   
         savedStart = start;
         savedEnd = end;
         start = lastStart;
         end = lastEnd;
         output;
         
         start = savedStart;
         end = lastEnd;
      end;
   end;
   
   lastStart = Start;
   lastEnd = End;
   
   if last.Antibiotic then do;
      output;
   end;
   
   /*format last: saved: date9.;*/
   
   drop last: saved:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Aug 2021 10:06:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/removing-gaps-between-treatment-dates-given-a-condition/m-p/761760#M30334</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-08-16T10:06:59Z</dc:date>
    </item>
    <item>
      <title>Re: removing gaps between treatment dates given a condition</title>
      <link>https://communities.sas.com/t5/New-SAS-User/removing-gaps-between-treatment-dates-given-a-condition/m-p/761804#M30336</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length antibiotic $200;
input patient antibiotic $ start:date9. end:date9.;
format start end date9.;
cards;
1 cipro 16APR2018 21APR2018
1 cipro 23APR2018 29APR2018
2 Cipro+flagyl 16APR2018 19APR2018
2 Cipro+flagyl 23APR2018 29APR2018
2 cipro 30JUN2018 29JUL2018
;
run;

data temp;
 set have;
 do date=start to end;
  output;
 end;
 format date date9.;
 drop start end;
run;
proc sort data=temp nodupkey;by patient antibiotic date;run;
data temp1;
 set temp;
 by patient antibiotic;
 if first.antibiotic or dif(date)&amp;gt;5 then group+1;
run;
proc summary data=temp1 ;
by group patient antibiotic;
var date;
output out=want min=start max=end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Aug 2021 13:57:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/removing-gaps-between-treatment-dates-given-a-condition/m-p/761804#M30336</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-08-16T13:57:52Z</dc:date>
    </item>
  </channel>
</rss>

