<?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 get the desired output data to determine treatment pattern? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/375360#M89979</link>
    <description>&lt;P&gt;The following still probably doesn't match all of your conditions, but does meet them for your examples:&lt;/P&gt;
&lt;PRE&gt;data have ;
  input (patient_id drug_name drug_type) ($) (start end) (: date11.);
  format start end  date9.;
  cards;
A11                        N1               Non_core   23-Apr-14   21-May-14
A11                        C1                 Core         27-Apr-14   25-May-14
A11                        C1                 Core         3-May-14   31-May-14
A11                        N1               Non_core   10-May-14   7-Jun-14
A11                        C2                  Core        11-May-14    8-Jun-14
A11                        N2               Non_core   12-May-14    9-Jun-14
A11                        C1                 Core         10-Jul-14      7-Aug-14
A11                        C1                 Core         15-Jul-14    12-Aug-14
A11                        C3                 Core         29-Jul-14     26-Aug-14
A11                        N4              Non_core     8-Sep-14       6-Oct-14
A11                        N2              Non_core     9-Sep-14      7-Oct-14
A11                        C1                Core           12-Sep-14    10-Oct-14
A11                        C1                Core           15-Sep-14    13-Oct-14
A11                        C1                Core           27-Sep-14     25-Oct-14
A11                        C3                Core            1-Jan-15        29-Jan-15
A11                        C1                 Core           3-Jan-15       31-Jan-15
A11                        C1                 Core            5-Jan-15       2-Feb-15
A11                        C1                 Core           10-Jan-15      7-Feb-15
A11                        N1              Non_core       15-Jan-15    12-Feb-15
A11                        N2              Non_core       18-Jan-15     15-Feb-15
;

data want
 (keep=patient_id drug start_date end_date lot)
 ;
  set have;
  by patient_id;
  format start_date end_date date9.;

  /* look ahead at next record */
  set have ( firstobs = 2 keep = start drug_type drug_name 
              rename = (start = next_start drug_type=next_type drug_name=next_drug) )
      have (      obs = 1 drop = _all_ );
  next_start = ifn(last.patient_id, (.), next_start );
 
  /* set length of drug to be wide enough to fix all drugs */
  length drug $200.;
  array adrugs(100) $
  adrug1-adrug100
/*   _temporary_ */
 ;
  array adates(100)
  adate1-adate100;
/*   _temporary_ */
 ;
  *format adate1-adate20 date9.;
  retain start_date end_date drug days adrug: adate:;
    
  /* initialize variables for first record within a given lot */
  if first.patient_id or counter eq 0 then do;
    if first.patient_id then do;
      call missing (of adrugs(*));
      call missing (of adates(*));
      dcounter=0;
    end;
    start_date=start;
    end_date=end;
    days=21;
    counter=1;
    drug='';
          
    if drug_type eq 'Core' then do;
      drug=drug_name;
      dcounter+1;
      adrugs(dcounter)=drug_name;
      adates(dcounter)=end;
      do i=1 to dim(adrugs);
        if (not missing(adrugs(i))) and adates(i) ge start_date and adrugs(i) ne strip(drug_name) then do;
          drug=catx('+',drug,adrugs(i));
          end_date=max(end_date,adates(i));
        end;
        else do;
          call missing(adrugs(i));
          call missing(adates(i));
        end;
      end;
    end;
  end;
  
  /* if not first record in lot and still within 21 day period check to see if drug in drug list */
  else if days eq 21 and start le Start_Date+21 then do;
    if drug_type eq 'Core' then do;
      if not findw(drug,strip(drug_name)) then do;
        drug=catx('+',drug,drug_name);
        dcounter+1;
        adrugs(dcounter)=drug_name;
        adates(dcounter)=end;
      end;
      do i=1 to dim(adrugs);
        if drug_name eq adrugs(i) and adates(i) lt start_date then do;
          adates(i)=end;
        end;
      end;
      counter+1;
      end_date=max(end_date,end);
    end;
    
    /* ignore record if Non_core and no core yet in lot */
    else if not missing(drug) then do;
      if not findw(drug,strip(drug_name)) then do;
        drug=catx('+',drug,drug_name);
        if drug_type='Core' then do;
          dcounter+1;
          adrugs(dcounter)=drug_name;
          adates(dcounter)=end;
        end;
      end;
      counter+1;
    end;
  end;

  /* within 60 day check */
  else do;
    days=60;
    if start le end_date+60 and findw(drug,strip(drug_name)) and drug_type eq 'Core' then do;
      counter+1;
      end_date=max(end,end_date);
      do i=1 to dim(adrugs);
        if adrugs(i) eq strip(drug_name) then do;
          adates(i)=max(adates(i),end);
        end;
      end;
    end;
  end;
*output;
  
  /* check to see if last.patient_id or next record indicates new lot */
  if last.patient_id or
     (counter gt 0 and
     days eq 60 and
     (next_start gt end_date+60 or
      ((not findw(drug,strip(next_drug))) and
       next_type eq 'Core')))
  then do;
    if not missing(next_start) and next_start le end_date then end_date=next_start-1;
    lot+1;
    output;
    counter=0;
  end;
run;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 12 Jul 2017 15:13:49 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2017-07-12T15:13:49Z</dc:date>
    <item>
      <title>How to get the desired output data to determine treatment pattern?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/374192#M89558</link>
      <description>&lt;P&gt;Reposting -&lt;/P&gt;&lt;P&gt;If anyone can help me in this ,I will be really obliged .I have to submit this in next 15 hours.Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having problem to create the desired output data.&lt;/P&gt;&lt;P&gt;I have to indentify the drugs which has been used in first 21 days and it will create initial line of treatment .but the below rules are applied to finalize the&amp;nbsp; line of treatment.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;The start date will be first use of any drug irrespective of core or no core&lt;/LI&gt;&lt;LI&gt;The end date will be last end date of last use of any core drug&lt;/LI&gt;&lt;LI&gt;If any core drug from initial line of treatment is found within 60 days from the end date of initial line of treatment then the end of initial line of treatment would be updated to end date of this indentified core drug. Again i have to check for 60 days gap and so on.&lt;/LI&gt;&lt;LI&gt;If a new core drug is identified (other than the core drug from initial line of treatment) before the end date of initial lot first lot will end one day before the start date of new core drug .Second line of treatment will be started from the start date of new core drug.&lt;/LI&gt;&lt;LI&gt;If there is no core drug from initial lot of treatment within 60 days of the end date of initial line of treatment, then second line of treatment will be started and the same above rule will be applied to find third or subsequent lots.&lt;/LI&gt;&lt;LI&gt;If there is any overlapping case like a core drug C1 is continue some days after starting of second line of treatment and it is again found any time after start of second line of treatment then the second line of treatment would contain the drugs from second line of treatment along with c1 .The end date will be the end of latest use of any core drug.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Data I have&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;patient_id &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drug_name &amp;nbsp; &amp;nbsp; &amp;nbsp; drug_type &amp;nbsp; &amp;nbsp; &amp;nbsp;start &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end&lt;BR /&gt;A11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;N1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Non_core &amp;nbsp; 23-Apr-14 &amp;nbsp; 21-May-14&lt;BR /&gt;A11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Core &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 27-Apr-14 &amp;nbsp; 25-May-14&lt;BR /&gt;A11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Core &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3-May-14 &amp;nbsp; 31-May-14&lt;BR /&gt;A11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;N1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Non_core &amp;nbsp; 10-May-14 &amp;nbsp; 7-Jun-14&lt;BR /&gt;A11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Core &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;11-May-14 &amp;nbsp; &amp;nbsp;8-Jun-14&lt;BR /&gt;A11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;N2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Non_core &amp;nbsp; 12-May-14 &amp;nbsp; &amp;nbsp;9-Jun-14&lt;BR /&gt;A11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Core &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10-Jul-14 &amp;nbsp; &amp;nbsp; &amp;nbsp;7-Aug-14&lt;BR /&gt;A11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Core &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 15-Jul-14 &amp;nbsp; &amp;nbsp;12-Aug-14&lt;BR /&gt;A11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Core &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 29-Jul-14 &amp;nbsp; &amp;nbsp; 26-Aug-14&lt;BR /&gt;A11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;N4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Non_core &amp;nbsp; &amp;nbsp; 8-Sep-14 &amp;nbsp; &amp;nbsp; &amp;nbsp; 6-Oct-14&lt;BR /&gt;A11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;N2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Non_core &amp;nbsp; &amp;nbsp; 9-Sep-14 &amp;nbsp; &amp;nbsp; &amp;nbsp;7-Oct-14&lt;BR /&gt;A11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Core &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12-Sep-14 &amp;nbsp; &amp;nbsp;10-Oct-14&lt;BR /&gt;A11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Core &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 15-Sep-14 &amp;nbsp; &amp;nbsp;13-Oct-14&lt;BR /&gt;A11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Core &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 27-Sep-14 &amp;nbsp; &amp;nbsp; 25-Oct-14&lt;BR /&gt;A11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Core &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1-Jan-15 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;29-Jan-15&lt;BR /&gt;A11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Core &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3-Jan-15 &amp;nbsp; &amp;nbsp; &amp;nbsp; 31-Jan-15&lt;BR /&gt;A11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Core &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5-Jan-15 &amp;nbsp; &amp;nbsp; &amp;nbsp; 2-Feb-15&lt;BR /&gt;A11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Core &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10-Jan-15 &amp;nbsp; &amp;nbsp; &amp;nbsp;7-Feb-15&lt;BR /&gt;A11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;N1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Non_core &amp;nbsp; &amp;nbsp; &amp;nbsp; 15-Jan-15 &amp;nbsp; &amp;nbsp;12-Feb-15&lt;BR /&gt;A11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;N2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Non_core &amp;nbsp; &amp;nbsp; &amp;nbsp; 18-Jan-15 &amp;nbsp; &amp;nbsp; 15-Feb-15&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data I want&amp;nbsp;&lt;/P&gt;&lt;P&gt;patient_id &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drug&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;start &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lot&lt;BR /&gt;A11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; C1+N1+C2+N2 &amp;nbsp; &amp;nbsp; &amp;nbsp; 23-Apr-14 &amp;nbsp; &amp;nbsp; &amp;nbsp;28-Jul-14 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;BR /&gt;A11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C3+C1+N4+N2 &amp;nbsp; &amp;nbsp; &amp;nbsp;29-Jul-14 &amp;nbsp; &amp;nbsp; &amp;nbsp; 25-Oct-14 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;BR /&gt;A11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; C3+C1+N1+N2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1-Jan-15 &amp;nbsp; &amp;nbsp; &amp;nbsp; 15-Feb-15 &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here lot represents line of treatment&lt;/P&gt;&lt;P&gt;In this data initially drugs found in first 21days are N1,c1,c1,n1,c2,n2 and the initial start date of lot 1 will be 4/23/2014 and initial end date will be the latest&amp;nbsp; use of any core drug which is 6/8/2014&lt;/P&gt;&lt;P&gt;Next I need to check if there is any core drug from initial lot is available within 60 days of end of initial lot . c1 from lot 1 is there within 60 days .so the new end date will be updated to 8/7/2014.Again I have to look for 60 days criteria. i found again c1 is available within 60 days. So the new end date would be 8/12/2014.But as per the rule above&amp;nbsp; there is a new core drug(other than the core drugs from initial lot) available before the end of initial line of treatment .so the first line of treatment will be end one day before the start date of newly indentified core drug. Then end of first lot is 7/28/2014.&lt;/P&gt;&lt;P&gt;Second line of treatment starts at 7/29/2014.the same above rules are applied here also to determine to end date .the drugs found in 21 days are C3, C1, N4, N2,C1.The initial end date will be 10/13/2014.There is an overlapping drug (C1) from lot 1 because latest use of C1 is 8/7/2014 which is after start of second lot and it is found again any time after start of lot 2.Then end date of second lot would be 10/25/2014.&lt;/P&gt;&lt;P&gt;As there is no drug found within 6o days so end of second lot, third lot will start at 1/1/2015.Same rule as above will be applied .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any leads would be helpful.Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2017 12:47:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/374192#M89558</guid>
      <dc:creator>ani_89</dc:creator>
      <dc:date>2017-07-11T12:47:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the desired output data to determine treatment pattern?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/374222#M89577</link>
      <description>&lt;P&gt;The following code isn't complete, and doesn't meet all of your conditions, but it should give you enough direction to enable you to fix the incomplete or wrong parts:&lt;/P&gt;
&lt;PRE&gt;data have;
  input (patient_id drug_name drug_type) ($) (start end) (: date11.);
  format start end  date9.;
  cards;
A11                        N1               Non_core   23-Apr-14   21-May-14
A11                        C1                 Core         27-Apr-14   25-May-14
A11                        C1                 Core         3-May-14   31-May-14
A11                        N1               Non_core   10-May-14   7-Jun-14
A11                        C2                  Core        11-May-14    8-Jun-14
A11                        N2               Non_core   12-May-14    9-Jun-14
A11                        C1                 Core         10-Jul-14      7-Aug-14
A11                        C1                 Core         15-Jul-14    12-Aug-14
A11                        C3                 Core         29-Jul-14     26-Aug-14
A11                        N4              Non_core     8-Sep-14       6-Oct-14
A11                        N2              Non_core     9-Sep-14      7-Oct-14
A11                        C1                Core           12-Sep-14    10-Oct-14
A11                        C1                Core           15-Sep-14    13-Oct-14
A11                        C1                Core           27-Sep-14     25-Oct-14
A11                        C3                Core            1-Jan-15        29-Jan-15
A11                        C1                 Core           3-Jan-15       31-Jan-15
A11                        C1                 Core            5-Jan-15       2-Feb-15
A11                        C1                 Core           10-Jan-15      7-Feb-15
A11                        N1              Non_core       15-Jan-15    12-Feb-15
A11                        N2              Non_core       18-Jan-15     15-Feb-15
;

data want (keep=patient_id drug start_date end_date lot);
  set have;
  by patient_id;
  retain start_date end_date drug end60;
  format start_date end_date date9.;
  set have ( firstobs = 2 keep = start drug_type drug_name 
              rename = (start = next_start drug_type=next_type drug_name=next_drug) )
      have (      obs = 1 drop = _all_ );
  next_start = ifn(last.patient_id, (.), next_start );
  if first.patient_id or counter eq 0 then do;
    start_date=start;
    end_date=end;
    if drug_type eq 'Core' then do;
      counter=1;
      drug=drug_name;
      end60=end+60;
    end;
    else do;
      drug='';
      counter=0;
    end;
  end;
  else if start le Start_Date+21 then do;
    if counter=0 then do;
      if drug_type eq 'Core' then do;
        drug=drug_name;
        counter=1;
        end60=end;
      end;
    end;
    else do;
      if not findw(drug,drug_name) then drug=catx('+',drug,drug_name);
      if drug_type eq 'Core' then do;
        counter+1;
        end_date=end;
      end;
    end;
  end;
  else if Start_Date le end60 and findw(drug,drug_name) and drug_type eq 'Core' then do;
    end60=end+60;
  end;
  if counter gt 0 and
     (next_start gt End60 or
     (counter gt 0 and
      not findw(drug,next_drug) and
      next_type eq 'Core' and
      next_start gt start_date+21)) or
      last.patient_id then do;
    end_date=start-1;
    lot+1;
    output;
    drug='';
    core='';
    counter=0;
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Sun, 09 Jul 2017 04:12:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/374222#M89577</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-09T04:12:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the desired output data to determine treatment pattern?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/374984#M89840</link>
      <description>&lt;P&gt;I don't think anyone can help unless you spend some time to review suggested code and help identify where it doesn't meet your specs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below is a slightly revised version of the code I originally proposed. It produces the correct result for the first lot, but not the others. I have to question why you think your second lot is correct (i.e.,&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;patient_id           drug                       start               end             lot
A11                  C3+C1+N4+N2      29-Jul-14       25-Oct-14        2
&lt;/PRE&gt;
&lt;P&gt;C3 starts on 29jul2014 and no other drugs are used in the first 21 days, so I don't understand why the other drugs are included.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the best I can do without further feedback:&lt;/P&gt;
&lt;PRE&gt;data have ;
  input (patient_id drug_name drug_type) ($) (start end) (: date11.);
  format start end  date9.;
  cards;
A11                        N1               Non_core   23-Apr-14   21-May-14
A11                        C1                 Core         27-Apr-14   25-May-14
A11                        C1                 Core         3-May-14   31-May-14
A11                        N1               Non_core   10-May-14   7-Jun-14
A11                        C2                  Core        11-May-14    8-Jun-14
A11                        N2               Non_core   12-May-14    9-Jun-14
A11                        C1                 Core         10-Jul-14      7-Aug-14
A11                        C1                 Core         15-Jul-14    12-Aug-14
A11                        C3                 Core         29-Jul-14     26-Aug-14
A11                        N4              Non_core     8-Sep-14       6-Oct-14
A11                        N2              Non_core     9-Sep-14      7-Oct-14
A11                        C1                Core           12-Sep-14    10-Oct-14
A11                        C1                Core           15-Sep-14    13-Oct-14
A11                        C1                Core           27-Sep-14     25-Oct-14
A11                        C3                Core            1-Jan-15        29-Jan-15
A11                        C1                 Core           3-Jan-15       31-Jan-15
A11                        C1                 Core            5-Jan-15       2-Feb-15
A11                        C1                 Core           10-Jan-15      7-Feb-15
A11                        N1              Non_core       15-Jan-15    12-Feb-15
A11                        N2              Non_core       18-Jan-15     15-Feb-15
;

data want (keep=patient_id drug start_date end_date lot);
  set have;
  by patient_id;
  retain start_date end_date drug days;
  format start_date end_date date9.;

  /* look ahead at next record */
  set have ( firstobs = 2 keep = start drug_type drug_name 
              rename = (start = next_start drug_type=next_type drug_name=next_drug) )
      have (      obs = 1 drop = _all_ );
  next_start = ifn(last.patient_id, (.), next_start );
 
  /* set length of drug to be wide enough to fix all drugs */
  length drug $200.;
  
  /* initialize variables for first record within a given lot */
  if first.patient_id or counter eq 0 then do;
    start_date=start;
    end_date=end;
    days=21;
    counter=1;
    drug='';
    
    if drug_type eq 'Core' then drug=drug_name;
  end;
  
  /* if not first record in lot and still within 21 day period check to see if drug in drug list */
  else if days eq 21 and start le Start_Date+21 then do;
    if drug_type eq 'Core' then do;
      if not findw(drug,strip(drug_name)) then drug=catx('+',drug,drug_name);
      counter+1;
      end_date=max(end_date,end+60);
    end;
    
    /* ignore record if Non_core and no core yet in lot */
    else if not missing(drug) then do;
      if not findw(drug,strip(drug_name)) then drug=catx('+',drug,drug_name);
      counter+1;
    end;
  end;

  /* within 60 day check */
  else do;
    days=60;
    if start le end_date and findw(drug,drug_name) and drug_type eq 'Core' then do;
      counter+1;
    end;
  end;
  /* check to see if last.patient_id or next record indicates new lot */
  if last.patient_id or
     (counter gt 0 and
     days eq 60 and
     (next_start gt end_date or
      ((not findw(drug,strip(next_drug))) and
       next_type eq 'Core')))
  then do;
    if not last.patient_id then end_date=next_start-1;
    lot+1;
    output;
    counter=0;
  end;
run;
&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Jul 2017 14:36:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/374984#M89840</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-11T14:36:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the desired output data to determine treatment pattern?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/375030#M89871</link>
      <description>&lt;P&gt;Thanks .The code works fine fot first line of treatment .Yes you are right .The N4 and N2 will not be included but C1 will be included because &amp;nbsp;the rule &amp;nbsp;says&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If there is any overlapping case like if any core drug from previous lot&amp;nbsp;&amp;nbsp; continues some days after starting of current&amp;nbsp;line of treatment (Here first line of treatments ends 28-Jul-14&amp;nbsp; but latest use of C1 from first lot ends on 12Aug2014 which is after start of lot 2 )&amp;nbsp; and it is again found any time after start of second line of treatment then the second line of treatment would contain the drugs from second line of treatment along with c1 or all the overlapping drug drugs as per the rules (here it is found after intitial 21 days after starting of lot 2 .) &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I need to check any time if any core drugs from previous lot are present in current lot or not .The end date will be the end of latest use of any core drug.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;patient_id &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drug&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;start &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lot&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;A11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; C1+N1+C2+N2 &amp;nbsp; &amp;nbsp; &amp;nbsp; 23-Apr-14 &amp;nbsp; &amp;nbsp; &amp;nbsp;28-Jul-14 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;A11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C3+C1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 29-Jul-14 &amp;nbsp; &amp;nbsp; &amp;nbsp; 25-Oct-14 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;A11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; C3+C1+N1+N2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1-Jan-15 &amp;nbsp; &amp;nbsp; &amp;nbsp; 7-Feb-15 &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2017 18:00:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/375030#M89871</guid>
      <dc:creator>ani_89</dc:creator>
      <dc:date>2017-07-11T18:00:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the desired output data to determine treatment pattern?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/375053#M89879</link>
      <description>&lt;P&gt;One more thing I want to add that the current &amp;nbsp;lot ends 1 day prior to sart of new core drug&amp;nbsp;only if a new core drug is identified in next&amp;nbsp;lot otherwise the lot ends on end date of latest use core drug in current lot.In our example lot 1 ends on 28Jul2014 because C3 is indentified (other than the cre drugs present in lot 1).But &amp;nbsp;in case of lot2 no new core drug is foundd (after applying 21 days and 60 days criteria) ,this lot 2 will end on end date of latest use of core drug from lot 2.Here the above overlapping rules also needs to be checkd .If you can help to implement these two logic that would be great for me.Then update treatment pattern would be as below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;patient_id &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drug&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;start &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lot&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;A11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; C1+N1+C2+N2 &amp;nbsp; &amp;nbsp; &amp;nbsp; 23-Apr-14 &amp;nbsp; &amp;nbsp; &amp;nbsp;28-Jul-14 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;A11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C3+C1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;29-Jul-14 &amp;nbsp; &amp;nbsp; &amp;nbsp; 25-Oct-14 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;A11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; C3+C1+N1+N2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1-Jan-15 &amp;nbsp; &amp;nbsp; &amp;nbsp; 7-Feb-15 &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The logic is I have to identified whatever drug are found in first 21 days .Then i have to check if there any core drug from the intitial 21 days are available within 60 days of end date of last use of core drugs within 21 days.But if a new core drug is found (other than the core drug from the intial 21 days drugs) then the lot ends one day prior to start date of this drug &amp;nbsp;.If no new core drug is found. the lot will continue to last end date &amp;nbsp;of core drug &amp;nbsp;which is &amp;nbsp;a core drug from intial 21 days.Then we need &amp;nbsp;to check the overlapping rule.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2017 19:16:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/375053#M89879</guid>
      <dc:creator>ani_89</dc:creator>
      <dc:date>2017-07-11T19:16:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the desired output data to determine treatment pattern?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/375103#M89899</link>
      <description>&lt;P&gt;Adding the code to adjust or not adjust end_time is easy. Your other requirement, the one that would include C1 in lot 2, would require more work and thought then I can justify spending in this forum. I'll have to leave that to you.&lt;/P&gt;
&lt;PRE&gt;data have ;
  input (patient_id drug_name drug_type) ($) (start end) (: date11.);
  format start end  date9.;
  cards;
A11                        N1               Non_core   23-Apr-14   21-May-14
A11                        C1                 Core         27-Apr-14   25-May-14
A11                        C1                 Core         3-May-14   31-May-14
A11                        N1               Non_core   10-May-14   7-Jun-14
A11                        C2                  Core        11-May-14    8-Jun-14
A11                        N2               Non_core   12-May-14    9-Jun-14
A11                        C1                 Core         10-Jul-14      7-Aug-14
A11                        C1                 Core         15-Jul-14    12-Aug-14
A11                        C3                 Core         29-Jul-14     26-Aug-14
A11                        N4              Non_core     8-Sep-14       6-Oct-14
A11                        N2              Non_core     9-Sep-14      7-Oct-14
A11                        C1                Core           12-Sep-14    10-Oct-14
A11                        C1                Core           15-Sep-14    13-Oct-14
A11                        C1                Core           27-Sep-14     25-Oct-14
A11                        C3                Core            1-Jan-15        29-Jan-15
A11                        C1                 Core           3-Jan-15       31-Jan-15
A11                        C1                 Core            5-Jan-15       2-Feb-15
A11                        C1                 Core           10-Jan-15      7-Feb-15
A11                        N1              Non_core       15-Jan-15    12-Feb-15
A11                        N2              Non_core       18-Jan-15     15-Feb-15
;

data want (keep=patient_id drug start_date end_date lot);
  set have;
  by patient_id;
  retain start_date end_date drug days;
  format start_date end_date date9.;

  /* look ahead at next record */
  set have ( firstobs = 2 keep = start drug_type drug_name 
              rename = (start = next_start drug_type=next_type drug_name=next_drug) )
      have (      obs = 1 drop = _all_ );
  next_start = ifn(last.patient_id, (.), next_start );
 
  /* set length of drug to be wide enough to fix all drugs */
  length drug $200.;
  
  /* initialize variables for first record within a given lot */
  if first.patient_id or counter eq 0 then do;
    start_date=start;
    end_date=end;
    days=21;
    counter=1;
    drug='';
    
    if drug_type eq 'Core' then drug=drug_name;
  end;
  
  /* if not first record in lot and still within 21 day period check to see if drug in drug list */
  else if days eq 21 and start le Start_Date+21 then do;
    if drug_type eq 'Core' then do;
      if not findw(drug,strip(drug_name)) then drug=catx('+',drug,drug_name);
      counter+1;
      end_date=max(end_date,end);
    end;
    
    /* ignore record if Non_core and no core yet in lot */
    else if not missing(drug) then do;
      if not findw(drug,strip(drug_name)) then drug=catx('+',drug,drug_name);
      counter+1;
    end;
  end;

  /* within 60 day check */
  else do;
    days=60;
    if start le end_date+60 and findw(drug,strip(drug_name)) and drug_type eq 'Core' then do;
      counter+1;
      end_date=max(end,end_date);
    end;
  end;
  
  /* check to see if last.patient_id or next record indicates new lot */
  if last.patient_id or
     (counter gt 0 and
     days eq 60 and
     (next_start gt end_date or
      ((not findw(drug,strip(next_drug))) and
       next_type eq 'Core')))
  then do;
    if next_start le end_date then end_date=next_start-1;
    lot+1;
    output;
    counter=0;
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2017 19:30:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/375103#M89899</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-11T19:30:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the desired output data to determine treatment pattern?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/375165#M89914</link>
      <description>&lt;P&gt;Thanks for your advice.I will spend time on this .But in the current senario ,the start of lot 3 should be 12sep2014 because lot 2 ends on 26aug2014 and within 60 days a new core drug C1 (other than the core drug from lot 2) &amp;nbsp;is found with a start date of 12sep2014 .So lot 3 begins here and continues till 25oct2014(but in currrently it is giving 9sep2014 as start date).From the end of lot 3 I have to check 60 days criteria ,if no core drug is found then lot 4 begins .C3 will lot4 intiative drug as it is found after 60 dayswith a start date of 1jan2015.but in current coding febit is not considering this and not included in lot 4.And also the end date of lot 4 should be 7feb2015 (lt is he end end date of latest use of core drug) .but currently it is coming as blank.Please if you can help me to corrrect these .&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 00:29:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/375165#M89914</guid>
      <dc:creator>ani_89</dc:creator>
      <dc:date>2017-07-12T00:29:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the desired output data to determine treatment pattern?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/375360#M89979</link>
      <description>&lt;P&gt;The following still probably doesn't match all of your conditions, but does meet them for your examples:&lt;/P&gt;
&lt;PRE&gt;data have ;
  input (patient_id drug_name drug_type) ($) (start end) (: date11.);
  format start end  date9.;
  cards;
A11                        N1               Non_core   23-Apr-14   21-May-14
A11                        C1                 Core         27-Apr-14   25-May-14
A11                        C1                 Core         3-May-14   31-May-14
A11                        N1               Non_core   10-May-14   7-Jun-14
A11                        C2                  Core        11-May-14    8-Jun-14
A11                        N2               Non_core   12-May-14    9-Jun-14
A11                        C1                 Core         10-Jul-14      7-Aug-14
A11                        C1                 Core         15-Jul-14    12-Aug-14
A11                        C3                 Core         29-Jul-14     26-Aug-14
A11                        N4              Non_core     8-Sep-14       6-Oct-14
A11                        N2              Non_core     9-Sep-14      7-Oct-14
A11                        C1                Core           12-Sep-14    10-Oct-14
A11                        C1                Core           15-Sep-14    13-Oct-14
A11                        C1                Core           27-Sep-14     25-Oct-14
A11                        C3                Core            1-Jan-15        29-Jan-15
A11                        C1                 Core           3-Jan-15       31-Jan-15
A11                        C1                 Core            5-Jan-15       2-Feb-15
A11                        C1                 Core           10-Jan-15      7-Feb-15
A11                        N1              Non_core       15-Jan-15    12-Feb-15
A11                        N2              Non_core       18-Jan-15     15-Feb-15
;

data want
 (keep=patient_id drug start_date end_date lot)
 ;
  set have;
  by patient_id;
  format start_date end_date date9.;

  /* look ahead at next record */
  set have ( firstobs = 2 keep = start drug_type drug_name 
              rename = (start = next_start drug_type=next_type drug_name=next_drug) )
      have (      obs = 1 drop = _all_ );
  next_start = ifn(last.patient_id, (.), next_start );
 
  /* set length of drug to be wide enough to fix all drugs */
  length drug $200.;
  array adrugs(100) $
  adrug1-adrug100
/*   _temporary_ */
 ;
  array adates(100)
  adate1-adate100;
/*   _temporary_ */
 ;
  *format adate1-adate20 date9.;
  retain start_date end_date drug days adrug: adate:;
    
  /* initialize variables for first record within a given lot */
  if first.patient_id or counter eq 0 then do;
    if first.patient_id then do;
      call missing (of adrugs(*));
      call missing (of adates(*));
      dcounter=0;
    end;
    start_date=start;
    end_date=end;
    days=21;
    counter=1;
    drug='';
          
    if drug_type eq 'Core' then do;
      drug=drug_name;
      dcounter+1;
      adrugs(dcounter)=drug_name;
      adates(dcounter)=end;
      do i=1 to dim(adrugs);
        if (not missing(adrugs(i))) and adates(i) ge start_date and adrugs(i) ne strip(drug_name) then do;
          drug=catx('+',drug,adrugs(i));
          end_date=max(end_date,adates(i));
        end;
        else do;
          call missing(adrugs(i));
          call missing(adates(i));
        end;
      end;
    end;
  end;
  
  /* if not first record in lot and still within 21 day period check to see if drug in drug list */
  else if days eq 21 and start le Start_Date+21 then do;
    if drug_type eq 'Core' then do;
      if not findw(drug,strip(drug_name)) then do;
        drug=catx('+',drug,drug_name);
        dcounter+1;
        adrugs(dcounter)=drug_name;
        adates(dcounter)=end;
      end;
      do i=1 to dim(adrugs);
        if drug_name eq adrugs(i) and adates(i) lt start_date then do;
          adates(i)=end;
        end;
      end;
      counter+1;
      end_date=max(end_date,end);
    end;
    
    /* ignore record if Non_core and no core yet in lot */
    else if not missing(drug) then do;
      if not findw(drug,strip(drug_name)) then do;
        drug=catx('+',drug,drug_name);
        if drug_type='Core' then do;
          dcounter+1;
          adrugs(dcounter)=drug_name;
          adates(dcounter)=end;
        end;
      end;
      counter+1;
    end;
  end;

  /* within 60 day check */
  else do;
    days=60;
    if start le end_date+60 and findw(drug,strip(drug_name)) and drug_type eq 'Core' then do;
      counter+1;
      end_date=max(end,end_date);
      do i=1 to dim(adrugs);
        if adrugs(i) eq strip(drug_name) then do;
          adates(i)=max(adates(i),end);
        end;
      end;
    end;
  end;
*output;
  
  /* check to see if last.patient_id or next record indicates new lot */
  if last.patient_id or
     (counter gt 0 and
     days eq 60 and
     (next_start gt end_date+60 or
      ((not findw(drug,strip(next_drug))) and
       next_type eq 'Core')))
  then do;
    if not missing(next_start) and next_start le end_date then end_date=next_start-1;
    lot+1;
    output;
    counter=0;
  end;
run;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 15:13:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/375360#M89979</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-12T15:13:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the desired output data to determine treatment pattern?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/375506#M90023</link>
      <description>&lt;P&gt;Thanks for you valuable time .I can replicate this code in my actual data.In some cases it is not giving me the perect results .Below are the two&amp;nbsp;cases .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data I have -&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;patient_id &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drug_name &amp;nbsp; &amp;nbsp; &amp;nbsp;drug_type &amp;nbsp; &amp;nbsp; &amp;nbsp;start &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end&lt;BR /&gt;A1012 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Peginterferon Alfa-2b &amp;nbsp; &amp;nbsp; &amp;nbsp;Non_core &amp;nbsp; &amp;nbsp; &amp;nbsp; 6-Aug-14 &amp;nbsp; &amp;nbsp; 2-Sep-14&lt;BR /&gt;A1012 Peginterferon Alfa-2b Non_core 2-Sep-14 29-Sep-14&lt;BR /&gt;A1012 Peginterferon Alfa-2b Non_core 8-Oct-14 4-Nov-14&lt;BR /&gt;A1012 Peginterferon Alfa-2b Non_core 5-Dec-14 1-Jan-15&lt;BR /&gt;A1012 Peginterferon Alfa-2b Non_core 8-Jan-15 6-Feb-15&lt;BR /&gt;A1012 Peginterferon Alfa-2b Non_core 6-Feb-15 5-Mar-15&lt;BR /&gt;A1012 Ipilimumab Core 3-Mar-15 23-Mar-15&lt;BR /&gt;A1012 Temozolomide Core 24-Jun-16 21-Jul-16&lt;BR /&gt;A101 Vemurafenib Core 25-Apr-14 24-May-14&lt;BR /&gt;A101 Vemurafenib Core 30-May-14 28-Jun-14&lt;BR /&gt;A101 Dabrafenib Core 2-Jul-14 31-Jul-14&lt;BR /&gt;A101 Dabrafenib Core 6-Aug-14 4-Sep-14&lt;BR /&gt;A101 Dabrafenib Core 24-Sep-14 23-Oct-14&lt;BR /&gt;A101 Trametinib Dimethyl Sulfoxide Core 24-Sep-14 22-Oct-14&lt;BR /&gt;A101 Trametinib Dimethyl Sulfoxide Core 24-Oct-14 14-Nov-14&lt;BR /&gt;A101 Dabrafenib Core 24-Oct-14 22-Nov-14&lt;BR /&gt;A101 Trametinib Dimethyl Sulfoxide Core 21-Nov-14 20-Dec-14&lt;BR /&gt;A101 Dabrafenib Core 21-Nov-14 20-Dec-14&lt;BR /&gt;A101 Dabrafenib Core 17-Dec-14 15-Jan-15&lt;BR /&gt;A101 Trametinib Dimethyl Sulfoxide Core 17-Dec-14 15-Jan-15&lt;BR /&gt;A101 Dabrafenib Core 5-Jan-15 3-Feb-15&lt;BR /&gt;A101 Temozolomide Core 10-Dec-15 14-Dec-15&lt;BR /&gt;A101 Dabrafenib Core 24-Sep-14 23-Oct-14&lt;BR /&gt;A101 Trametinib Dimethyl Sulfoxide Core 24-Sep-14 22-Oct-14&lt;BR /&gt;A101 Trametinib Dimethyl Sulfoxide Core 24-Oct-14 14-Nov-14&lt;BR /&gt;A101 Dabrafenib Core 24-Oct-14 22-Nov-14&lt;BR /&gt;A101 Trametinib Dimethyl Sulfoxide Core 21-Nov-14 20-Dec-14&lt;BR /&gt;A101 Dabrafenib Core 21-Nov-14 20-Dec-14&lt;BR /&gt;A101 Dabrafenib Core 17-Dec-14 15-Jan-15&lt;BR /&gt;A101 Trametinib Dimethyl Sulfoxide Core 17-Dec-14 15-Jan-15&lt;BR /&gt;A101 Dabrafenib Core 5-Jan-15 3-Feb-15&lt;BR /&gt;A101 Temozolomide Core 10-Dec-15 14-Dec-15&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data line of treatmentment I am getting hrough this code-&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;patient id &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drug &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;start_LOT &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end_LOT &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;LOT&lt;BR /&gt;A102 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6-Aug-14 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2-Sep-14 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;A102 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5-Dec-14 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1-Jan-15 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;BR /&gt;A102 &amp;nbsp; &amp;nbsp; Ipilimumab+Ipilimum 3-Mar-15 &amp;nbsp; &amp;nbsp; &amp;nbsp;23-Mar-15 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;BR /&gt;A101 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Vemurafenib &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;25-Apr-14 &amp;nbsp; &amp;nbsp; 28-Jun-14 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;BR /&gt;A101 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Dabrafenib &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2-Jul-14 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;23-Sep-14 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;BR /&gt;A101 Trametinib Dimethyl Sulfoxide+Dabrafenib 24-Sep-14 3-Feb-15 3&lt;BR /&gt;A101 Temozolomide 10-Dec-15 14-Dec-15 4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data I want to have -&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;patient id &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drug &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;start_date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end_date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; LOT&lt;BR /&gt;A1012 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Peginterferon Alfa-2b &amp;nbsp; 6-Aug-14 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2-Mar-15 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;BR /&gt;A1012 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Ipilimumab &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3-Mar-15 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 23-Mar-15 &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;BR /&gt;A1012 Temozolomide 24-Jun-16 21-Jul-16 3&lt;BR /&gt;A101 Vemurafenib 25-Apr-14 28-Jun-14 1&lt;BR /&gt;A101 Dabrafenib 2-Jul-14 23-Sep-14 2&lt;BR /&gt;A101 Trametinib Dimethyl Sulfoxide+Dabrafenib 24-Sep-14 3-Feb-15 3&lt;BR /&gt;A101 Temozolomide 10-Dec-15 14-Dec-15 4&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;For patient is A102-&lt;/P&gt;&lt;P&gt;I forgot to mention that if in initial 21 days period all drugs found are non core then it will be treated same as core drugs and all rules would be applied same like core drugs.In this code we are not considering or dicard if there are no core drugs in initial 21 days &amp;nbsp;.For this reason I am getting blank lot in the result as above and wherever there are non core drug in initial 21 days or ther is only non core drug available for a patient.I did not get how to handle this in the code.Also some drug&amp;nbsp;name is getting truncated..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also if if a patient have only noncore drugs and no core drug are there. it would treated same as core drugs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For patient is A101-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First two lot matches perfectly but lot 3 doest not match as&amp;nbsp;Dabrafenib continues sometimes after stomties from the starting of lot 3.&lt;/P&gt;&lt;P&gt;and again start anytime after the start of lot 3.this the overlapping case as i mentined aboved yesterday.The end date would end of end latest use of core drugs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It would be really helpful if you can help me to handle above two scenarios ..Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 20:27:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/375506#M90023</guid>
      <dc:creator>ani_89</dc:creator>
      <dc:date>2017-07-12T20:27:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the desired output data to determine treatment pattern?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/375512#M90027</link>
      <description>&lt;P&gt;I can't tell anything from the data you posted. Post the data in the form of a data step and place it in the box you get when you click the {i} icon.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data you posted showed patient_ids of A1012 folowed by A101, but your results were for A102 and A101.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, the patient_IDs have to be in alpha order or the code won't work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second, since your drug names were a log longer and more complex than you originally indicated, all of the fields and arrays that capture them have to be modified to accept the longer lengths. However, one can't know those lengths without reviewing ALL of your actual data, thus those are answers you have to provide:&lt;/P&gt;
&lt;P&gt;1. What is the longest of any of the drug names?&lt;/P&gt;
&lt;P&gt;2. What is the maximum number of core drugs that might be included in a given lot&lt;/P&gt;
&lt;P&gt;3. What is the maximum number of core and non-core drugs that might be included in a given lot.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without those answers, and some representative test&amp;nbsp;data, I can't be of any further help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, on further review of what you want from what you posted, why would you expect non-core drugs to be added if no core drugs were used in the first 21 days? The current logic only accepted drugs if a core drug was used in the first 21 days.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 21:06:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/375512#M90027</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-12T21:06:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the desired output data to determine treatment pattern?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/375729#M90116</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data have;
length patient_id $15. drug_name $50. ;
input patient_id (drug_name drug_type) ($) (start end) (: date11.);
  format start end  date9.;
  cards;
13213	Vemurafenib	Core	12AUG2014	10SEP2014
13213	Vemurafenib	Core	05SEP2014	04OCT2014
13213	Vemurafenib	Core	03OCT2014	01NOV2014
13213	Vemurafenib	Core	03NOV2014	02DEC2014
13213	Vemurafenib	Core	08DEC2014	06JAN2015
13213	Vemurafenib	Core	05JAN2015	03FEB2015
13213	Vemurafenib	Core	06FEB2015	07MAR2015
13213	Vemurafenib	Core	13MAR2015	11APR2015
13213	Vemurafenib	Core	13APR2015	12MAY2015
13213	Vemurafenib	Core	14MAY2015	12JUN2015
13213	Vemurafenib	Core	11JUN2015	10JUL2015
13213	Vemurafenib	Core	14JUL2015	12AUG2015
13213	Vemurafenib	Core	12AUG2015	10SEP2015
13213	Vemurafenib	Core	15SEP2015	14OCT2015
13213	Vemurafenib	Core	13OCT2015	11NOV2015
13213	Vemurafenib	Core	17NOV2015	14DEC2015
13213	Vemurafenib	Core	11DEC2015	07JAN2016
13213	Vemurafenib	Core	11JAN2016	07FEB2016
13213	Cobimetinib	Core	20JAN2016	16FEB2016
13213	Vemurafenib	Core	11FEB2016	09MAR2016
13213	Cobimetinib	Core	11FEB2016	09MAR2016
13213	Vemurafenib	Core	21MAR2016	17APR2016
13213	Cobimetinib	Core	21MAR2016	17APR2016
13213	Vemurafenib	Core	19APR2016	16MAY2016
13213	Cobimetinib	Core	19APR2016	16MAY2016
13213	Vemurafenib	Core	18MAY2016	14JUN2016
13213	Cobimetinib	Core	18MAY2016	14JUN2016
13213	Vemurafenib	Core	14JUN2016	11JUL2016
13213	Cobimetinib	Core	16JUN2016	13JUL2016
1124567	Dasatinib	Non_core	02JUN2014	01JUL2014
1124567	Dasatinib	Non_core	11JUL2014	09AUG2014
1124567	Dasatinib	Non_core	07AUG2014	05SEP2014
1124567	Dasatinib	Non_core	03SEP2014	02OCT2014
1414197	Interferon-Alfa-2b	Non_core	08JUN2015	05JUL2015
1414197	Interferon-Alfa-2b	Non_core	11JUL2015	07AUG2015
1414197	Interferon-Alfa-2b	Non_core	01AUG2015	28AUG2015
1414197	Interferon-Alfa-2b	Non_core	21AUG2015	17SEP2015
1414197	Interferon-Alfa-2b	Non_core	19SEP2015	16OCT2015
1414197	Interferon-Alfa-2b	Non_core	26OCT2015	22NOV2015
1414197	Interferon-Alfa-2b	Non_core	16NOV2015	16DEC2015
1414197	Interferon-Alfa-2b	Non_core	14DEC2015	13JAN2016
1414197	Interferon-Alfa-2b	Non_core	08JAN2016	07FEB2016
1414197	Interferon-Alfa-2b	Non_core	09FEB2016	10MAR2016
1414197	Interferon-Alfa-2b	Non_core	10MAR2016	09APR2016
1414197	Interferon-Alfa-2b	Non_core	05APR2016	05MAY2016
1414197	Interferon-Alfa-2b	Non_core	10MAY2016	30MAY2016
746461       PegInterferon-Alfa-2b Non_core   6-Aug-14     2-Sep-14
746461       PegInterferon-Alfa-2b Non_core  2-Sep-14    29-Sep-14
746461       PegInterferon-Alfa-2b Non_core  8-Oct-14    4-Nov-14
746461       PegInterferon-Alfa-2b Non_core  5-Dec-14    1-Jan-15
746461       PegInterferon-Alfa-2b Non_core  8-Jan-15    6-Feb-15
746461       PegInterferon-Alfa-2b Non_core  6-Feb-15    5-Mar-15
746461       Ipilimumab            Core      3-Mar-15    23-Mar-15
746461       Temozolomide          Core      24-Jun-16   21-Jul-16
;&lt;/PRE&gt;&lt;P&gt;Sir,thanks a lot for your valueable time &amp;nbsp;.I have to implemennt the below criterias.Please help me .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is one extract of orginal data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. The longest of any drug name is&amp;nbsp;TRAMETINIB DIMETHYL SULFOXIDE;&lt;/P&gt;&lt;P&gt;2.Max number of core drugs which can be included is 15.&lt;/P&gt;&lt;P&gt;3.Max number of core and non core drugs can be included is 30.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just given a situation where all the rules can be applied .But in the original data which i posted above .There might be 3 situations.&lt;/P&gt;&lt;P&gt;1.There may be cases where in intitial 21 days core and non core drugs -&amp;nbsp;&lt;/P&gt;&lt;P&gt;2.&lt;SPAN&gt;There may be cases where in intitial 21 days core &amp;nbsp;drugs only&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3.There may be cases where in intitial 21 days&amp;nbsp; non core drug only&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Situation 3 is not captured in current coding can you please where i need to change to capture situation 3.I noticed it after getting the original data.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Rules for only non core drugs within initial 21 days are same as core drugs .this a ideal case for patient id&amp;nbsp;1124567 .&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Only overlapping rules is not applied for non core drugs only in initial 21 days .&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;one more thing i want o add in the rule for endinding of lot&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;SPAN&gt;if there is is &amp;nbsp;a gap of at least 60 days after ending of a lot (no &amp;nbsp;core or non core drug is found in this 60 days) then next lot will begin&amp;nbsp;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;Or there is a new core drug other than the drug from previous lot is identifed within 60 days &amp;nbsp;of latest use of drugs.&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;SPAN&gt;Point 1 is not applied properly in the code I think when i was checking manually.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The data I want -&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Patient_id &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; start_date &amp;nbsp; &amp;nbsp; &amp;nbsp;end_date &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;drug &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lot&lt;BR /&gt;13213 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12AUG2014 &amp;nbsp; &amp;nbsp;19JAN2016 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Vemurafenib &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;13213 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20JAN2016 &amp;nbsp; &amp;nbsp; 13JUL2016 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Cobimetinib+Vemurafenib &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;BR /&gt;1124567 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;02JUN2014 &amp;nbsp; &amp;nbsp; 02OCT2014 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Dasatinib &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;BR /&gt;1414197 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;08JUN2015 &amp;nbsp; &amp;nbsp; 30MAY2016 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Interferon-Alfa-2b &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;746461 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6-Aug-14 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2-Mar-15 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PegInterferon-Alfa-2b &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;BR /&gt;746461 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3-Mar-15 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 23-Mar-15 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Ipilimumab &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;BR /&gt;746461 &amp;nbsp; &amp;nbsp; &amp;nbsp; 24 June 2016 &amp;nbsp; &amp;nbsp;21 July 2016 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Temozolomide &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;For patient_id -13213 the first drug indentified is Vemurafenib .after applying 60 days critera we got it ends one day befor a new core drug Cobimetinib starts and lot 2 starts here .but Vemurafenib contnues till 07FEB2016 which is after start of lot 2 and again it starts on 11FEB2016 .this is an overlapping situation . overlapping rules- If any drug core drug from previous regimen contnues after starting of current lot and they are found in again any time (within 21 days or 60 days )it would be included in current lot and end date would be the end date of latest use core drug. Again 21 days and 60 days criteria to be applied to idendentify start date ,end date and drugs.So lot 2 ends on 13JUL2016.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;For patient id 1124567 -no core is found within 21 days so it needs to be treated the same way we treat a core drug .we need no check if there is any Dasatinib (a non core drug) withing 60 days if found a non core drug then the end date update accordings .AS there is no other core drug or no non core drugs is found within 60 days of end date of lot 1 ends here.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;For patient id 1414197 --no core is found within 21 days so it needs to be treated the same way we treat a core drug .we need no check if there is any Interferon-Alfa-2b (a non core drug) withing 60 days if found a non core drug then the end date update accordings .AS there is no other core drug or no non core drugs is found within 60 days of end date of lot 1 ends here.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;For patient_id - 746461 in intial 21 days we found only a non core drug PegInterferon-Alfa-2b .so we need to treat this as i mentioned above .then check for 60 days gap from the end date date of latest use drug in initial 21 days and it is found that PegInterferon-Alfa-2b it start on again 02SEP2014.now again 60 days criteria and so on. This step is to be repeated until either no non-core drugs from LOT1 are identified in that period or a core drug is identified. a new core drug Ipilimumab is found on 03MAR2015 so lot 1 end on 02MAR2015 .lot 2 begins on 03MAR2015.again i need to check 21 days and 60 days critera as above.after applying this we got lot 2 ends on 23MAR2015 as a new core drug Temozolomide starts on 24JUN2016.so lot 3 begins here and after applying 21 days and 60 days criteria we get lot 3 ends on 21JUL2016.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But the data i am getting after running the code-&lt;/P&gt;&lt;P&gt;Patient_id &amp;nbsp; &amp;nbsp; &amp;nbsp; start_date &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end_date &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drug &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;lot&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;13213 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12AUG2014 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;19JAN2016 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Vemurafenib+Vemurafe &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;BR /&gt;13213 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20JAN2016 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 09MAR2016 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Cobimetinib+Cobimeti &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;BR /&gt;13213 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 21MAR2016 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 13JUL2016 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Vemurafenib+Vemurafe+Cobimetinib &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;BR /&gt;1124567 &amp;nbsp; &amp;nbsp; 02JUN2014 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01JUL2014 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;1124567 &amp;nbsp; &amp;nbsp; 03SEP2014 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;02OCT2014 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;BR /&gt;1414197 &amp;nbsp; &amp;nbsp; 08JUN2015 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;05JUL2015 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;BR /&gt;1414197 &amp;nbsp; &amp;nbsp;19SEP2015 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;16OCT2015 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;BR /&gt;1414197 &amp;nbsp; &amp;nbsp;08JAN2016 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 07FEB2016 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;BR /&gt;1414197 &amp;nbsp; &amp;nbsp;10MAY2016 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;30MAY2016 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&lt;BR /&gt;746461 &amp;nbsp; &amp;nbsp; 06 August 2014 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;02 September2014 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;746461 &amp;nbsp; &amp;nbsp; 05December2014 &amp;nbsp; &amp;nbsp;01 January 2015 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;BR /&gt;746461 &amp;nbsp; &amp;nbsp; 03March2015 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 23 March 2015 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Ipilimumab+Ipilimum &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jul 2017 15:12:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/375729#M90116</guid>
      <dc:creator>ani_89</dc:creator>
      <dc:date>2017-07-13T15:12:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the desired output data to determine treatment pattern?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/375841#M90147</link>
      <description>&lt;P&gt;Tthese are some othe cases where am not geeting the desired output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For patient id 1345268 - Core drug Dabranib starts on 11oct2013 and within 21 days no core or non core drugs is available .Dabranib's latest end is 8nov2013.From here we need to check within 60 days any core drug from initial 21 days is available or not (this rule applies for lot where only core drugs in intial 21 days of start of lot or core and non core drugs in intial 21 days of start of lot.But for only non core drugs in intial 21 days of start of lot, we nned to look for non core drug from intial 21 days ).in this case a new core drug Trametinib_Dimethyl_Sulfoxide is started ,so lot one will be ended one day prior o start of this new core drug.(if intial 21 days ,we get onlynon core drugs then we look for a new non core drug to start a new lot ).So lot 2 starts on 8nov2013.It check agais now as per the above rule 21 days and 60 days criteria.but from last lot Dabranib end on the same day when lot 2 starts.Darbanib again starts on 3dec2014 which is a overlapping situation and this needs to be included in lot 2 and end date would be the end date of max end date of all the drugs used in respective lot.in this case Darbanib continues till 1 jan2014.so lt 2 ends here.But in our curent coding it is giving a different result.&lt;BR /&gt;For Patient id 1345269 -A non core drug only available in initial 21 days .Soit needs to be considered I mentioned .Then check for core or non core drug within 60 days .if no core or non core drug found within 60 days then a new lot will begin.think we are missing this condition in our code .but i did not get how to handle this in the code.this is the same case for patient id 746461 and we are not getting Temozolomide in our lot.&lt;BR /&gt;For patient id 1345270 -A core drug Dabraenib starts on 24mar14 .After applying 21 days and 60 dyas criteria we get lot1 ends on 5aug2014.A new core drug Vemurafenib starts on 7aug2014 so l0t 2 begins here .After applying 21 days and 60 dyas critera we got lot 2 ends on 5sep2014.Again a new core drug Trametinib_Dimethyl_Sulfoxide starts so lot 3 begins here and after applying 21 days and 60 days criteria we got lot 3 ends on 27 jan2014.rest lotsare matcing .Pleasehelpme to resolv these.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help help to resolve this.I am alomst able to repicate the code to get the desired output.Only above three cases and those i mentioned in my above post i have am missing ou.It wiould really helpful for me if &amp;nbsp;look into this .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;How to handle the overlapping case a mentioned in mthis post and my previous post&lt;/LI&gt;&lt;LI&gt;If a regimen start with only noncore drug in initial 21 days- need to treat in the same way wear doing for core drugs.(onlly do not need to check overlapping condion for non core drugs).&lt;/LI&gt;&lt;LI&gt;If there is a gap of 60 or days or more(no core or non core drug is available in this gap ) after end of a lot and start of another instances next lot begins here.&lt;/LI&gt;&lt;LI&gt;How to handle the trucation of drugs.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data have;
length patient_id $15. drug_name $50. ;
input patient_id (drug_name drug_type) ($) (start end) (: date11.);
  format start end  date9.;
  cards;
1345268	Dabrafenib	Core	11-Oct-13	8-Nov-13
1345268	Dabrafenib	Core	4-Nov-13	3-Dec-13
1345268	Trametinib_Dimethyl_Sulfoxide	Core	8-Nov-13	7-Dec-13
1345268	Trametinib_Dimethyl_Sulfoxide	Core	2-Dec-13	31-Dec-13
1345268	Dabrafenib	Core	3-Dec-13	1-Jan-14
1345269	Interferon-Alfa-2b	Non_core	31-Oct-13	22-Jan-14
1345269	Vemurafenib	Core	16-Apr-14	15-May-14
1345270	Dabrafenib	Core	24-Mar-14	22-Apr-14
1345270	Trametinib_Dimethyl_Sulfoxide	Core	24-Mar-14	22-Apr-14
1345270	Dabrafenib	Core	17-Apr-14	16-May-14
1345270	Trametinib_Dimethyl_Sulfoxide	Core	17-Apr-14	16-May-14
1345270	Trametinib_Dimethyl_Sulfoxide	Core	21-May-14	19-Jun-14
1345270	Dabrafenib	Core	7-Jul-14	5-Aug-14
1345270	Trametinib_Dimethyl_Sulfoxide	Core	7-Jul-14	5-Aug-14
1345270	Vemurafenib	Core	7-Aug-14	5-Sep-14
1345270	Trametinib_Dimethyl_Sulfoxide	Core	7-Aug-14	5-Sep-14
1345270	Dabrafenib	Core	3-Oct-14	1-Nov-14
1345270	Trametinib_Dimethyl_Sulfoxide	Core	3-Oct-14	1-Nov-14
1345270	Dabrafenib	Core	29-Dec-14	27-Jan-15
1345270	Temozolomide	Core	31-Mar-15	27-Apr-15
1345270	Temozolomide	Core	23-Apr-15	20-May-15
1345270	Temozolomide	Core	28-May-15	24-Jun-15
1345270	Temozolomide	Core	17-Jun-15	7-Jul-15
1345270	Trametinib_Dimethyl_Sulfoxide	Core	20-Jul-15	18-Aug-15
1345270	Dabrafenib	Core	20-Jul-15	18-Aug-15
1345270	Trametinib_Dimethyl_Sulfoxide	Core	20-Aug-15	18-Sep-15
1345270	Dabrafenib	Core	20-Aug-15	18-Sep-15
1345270	Trametinib_Dimethyl_Sulfoxide	Core	24-Sep-15	23-Oct-15
1345270	Dabrafenib	Core	15-Oct-15	13-Nov-15
1345270	Trametinib_Dimethyl_Sulfoxide	Core	3-Nov-15	2-Dec-15
1345270	Dabrafenib	Core	19-Nov-15	18-Dec-15
1345270	Trametinib_Dimethyl_Sulfoxide	Core	17-Dec-15	15-Jan-16

;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data I want&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;patient_id &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drug &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; start &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end&lt;BR /&gt;1345268 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dabrafenib &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 11-Oct-13 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7-Nov-13&lt;BR /&gt;1345268 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Trametinib_Dimethyl_Sulfoxide,Dabrafenib &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;8-Nov-13 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1-Jan-14&lt;BR /&gt;1345269 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Interferon-Alfa-2b &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 31-Oct-13 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 22-Jan-14&lt;BR /&gt;1345269 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Vemurafenib &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 16-Apr-14 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 15-May-14&lt;BR /&gt;1345270 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dabrafenib,Trametinib_Dimethyl_Sulfoxide &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 24-Mar-14 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5-Aug-14&lt;BR /&gt;1345270 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Vemurafenib &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;7-Aug-14 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5-Sep-14&lt;BR /&gt;1345270 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dabrafenib,Trametinib_Dimethyl_Sulfoxide &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3-Oct-14 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 27-Jan-15&lt;BR /&gt;1345270 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Temozolomide &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 31-Mar-15 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;7-Jul-15&lt;BR /&gt;1345270 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dabrafenib,Trametinib_Dimethyl_Sulfoxide &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20-Jul-15 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 15-Jan-16&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jul 2017 21:35:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/375841#M90147</guid>
      <dc:creator>ani_89</dc:creator>
      <dc:date>2017-07-13T21:35:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the desired output data to determine treatment pattern?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/375966#M90188</link>
      <description>&lt;P&gt;Sir did you get a chance to look into why I am not getting the desired output in the actual data I have provided in case of overlapping case.Over lapping case being is being taken care of in the example data I have provided (The C1,N1 data) but not in actual.Also the cases where intital 21 days ,there are all non core drugs.It would be really helpful for me if you can look into this once.&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 10:52:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/375966#M90188</guid>
      <dc:creator>ani_89</dc:creator>
      <dc:date>2017-07-14T10:52:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the desired output data to determine treatment pattern?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/376065#M90207</link>
      <description>&lt;P&gt;OK, I looked into it, and corrected some of the issues you mentioned, but I do have to point something out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The purpose of the forum is to help others learn how to program in SAS. Other than the SAS staff who chime in sometime, the rest of us are just users like you and don't get paid for helping out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As such, we're not here to do other people's work, just provide you with enough help so that you can figure the rest out on your own. Besides, you know your data, tasks and requirements better than any of us could, so the correctness and fine tuning of any code is best left to you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, Analyst Finder.com&lt;/P&gt;
&lt;PRE&gt;data have;
  informat patient_id $15. drug_name $30. ;
  infile cards delimiter='09'x;
  input patient_id drug_name drug_type $ (start end) (: date9.);
  format start end  date9.;
  format drug_name $30.;
  cards;
13213	Vemurafenib	Core	12AUG2014	10SEP2014
13213	Vemurafenib	Core	05SEP2014	04OCT2014
13213	Vemurafenib	Core	03OCT2014	01NOV2014
13213	Vemurafenib	Core	03NOV2014	02DEC2014
13213	Vemurafenib	Core	08DEC2014	06JAN2015
13213	Vemurafenib	Core	05JAN2015	03FEB2015
13213	Vemurafenib	Core	06FEB2015	07MAR2015
13213	Vemurafenib	Core	13MAR2015	11APR2015
13213	Vemurafenib	Core	13APR2015	12MAY2015
13213	Vemurafenib	Core	14MAY2015	12JUN2015
13213	Vemurafenib	Core	11JUN2015	10JUL2015
13213	Vemurafenib	Core	14JUL2015	12AUG2015
13213	Vemurafenib	Core	12AUG2015	10SEP2015
13213	Vemurafenib	Core	15SEP2015	14OCT2015
13213	Vemurafenib	Core	13OCT2015	11NOV2015
13213	Vemurafenib	Core	17NOV2015	14DEC2015
13213	Vemurafenib	Core	11DEC2015	07JAN2016
13213	Vemurafenib	Core	11JAN2016	07FEB2016
13213	Cobimetinib	Core	20JAN2016	16FEB2016
13213	Vemurafenib	Core	11FEB2016	09MAR2016
13213	Cobimetinib	Core	11FEB2016	09MAR2016
13213	Vemurafenib	Core	21MAR2016	17APR2016
13213	Cobimetinib	Core	21MAR2016	17APR2016
13213	Vemurafenib	Core	19APR2016	16MAY2016
13213	Cobimetinib	Core	19APR2016	16MAY2016
13213	Vemurafenib	Core	18MAY2016	14JUN2016
13213	Cobimetinib	Core	18MAY2016	14JUN2016
13213	Vemurafenib	Core	14JUN2016	11JUL2016
13213	Cobimetinib	Core	16JUN2016	13JUL2016
1124567	Dasatinib	Non_core	02JUN2014	01JUL2014
1124567	Dasatinib	Non_core	11JUL2014	09AUG2014
1124567	Dasatinib	Non_core	07AUG2014	05SEP2014
1124567	Dasatinib	Non_core	03SEP2014	02OCT2014
1414197	Interferon-Alfa-2b	Non_core	08JUN2015	05JUL2015
1414197	Interferon-Alfa-2b	Non_core	11JUL2015	07AUG2015
1414197	Interferon-Alfa-2b	Non_core	01AUG2015	28AUG2015
1414197	Interferon-Alfa-2b	Non_core	21AUG2015	17SEP2015
1414197	Interferon-Alfa-2b	Non_core	19SEP2015	16OCT2015
1414197	Interferon-Alfa-2b	Non_core	26OCT2015	22NOV2015
1414197	Interferon-Alfa-2b	Non_core	16NOV2015	16DEC2015
1414197	Interferon-Alfa-2b	Non_core	14DEC2015	13JAN2016
1414197	Interferon-Alfa-2b	Non_core	08JAN2016	07FEB2016
1414197	Interferon-Alfa-2b	Non_core	09FEB2016	10MAR2016
1414197	Interferon-Alfa-2b	Non_core	10MAR2016	09APR2016
1414197	Interferon-Alfa-2b	Non_core	05APR2016	05MAY2016
1414197	Interferon-Alfa-2b	Non_core	10MAY2016	30MAY2016
746461	PegInterferon-Alfa-2b	Non_core	6Aug2014	2Sep2014
746461	PegInterferon-Alfa-2b	Non_core	2Sep2014	29Sep2014
746461	PegInterferon-Alfa-2b	Non_core	8Oct2014	4Nov2014
746461	PegInterferon-Alfa-2b	Non_core	5Dec2014	1Jan2015
746461	PegInterferon-Alfa-2b	Non_core	8Jan2015	6Feb2015
746461	PegInterferon-Alfa-2b	Non_core	6Feb2015	5Mar2015
746461	Ipilimumab	Core	3Mar2015	23Mar2015
746461	Temozolomide	Core	24Jun2016	21Jul2016
;

data want
 (keep=patient_id drug start_date end_date lot)
 ;
  set have;
  by patient_id notsorted;
  format start_date end_date date9.;

  /* look ahead at next record */
  set have ( firstobs = 2 keep = start drug_type drug_name 
              rename = (start = next_start drug_type=next_type drug_name=next_drug) )
      have (      obs = 1 drop = _all_ );
  next_start = ifn(last.patient_id, (.), next_start );
  next_type = ifc(last.patient_id, (.), next_type );
  next_drug = ifc(last.patient_id, (.), next_drug );
 
  /* set length of drug to be wide enough to fix all drugs */
  length drug $1000.;
  length hold_drug $1000.;
  array adrugs(100) $ 30 adrug1-adrug100;
  array adates(100) adate1-adate100;

  array hold_drugs(100) $ 30  hold_drug1-hold_drug100;
  array hold_dates(100) hold_date1-hold_date100;

 format adate1-adate20 date9.;
  retain start_date end_date drug days adrug: adate: hold_drug: hold_date:;
    
  /* initialize variables for first record within a given lot */
  if first.patient_id or counter eq 0 then do;
    if first.patient_id then do;
      lot=0;
      call missing (of adrugs(*));
      call missing (of adates(*));
      call missing (of hold_drugs(*));
      call missing (of hold_dates(*));
      dcounter=0;
    end;
    start_date=start;
    end_date=end;
    counter=1;
    drug='';
    hold_drug='';
          
    if drug_type eq 'Core' then do;
      drug=drug_name;
      dcounter+1;
      adrugs(dcounter)=drug_name;
      adates(dcounter)=end;
      do i=1 to dim(adrugs);
        if (not missing(adrugs(i))) and adates(i) ge start_date then do;
          if adrugs(i) ne strip(drug_name) then do;
            drug=catx('+',drug,adrugs(i));
            end_date=max(end_date,adates(i));
          end;
        end;
        else do;
          call missing(adrugs(i));
          call missing(adates(i));
        end;
      end;
    end;
    else do;
      call missing (of hold_drugs(*));
      call missing (of hold_dates(*));
      hold_drug=drug_name;
      dcounter+1;
      hold_drugs(dcounter)=drug_name;
      hold_dates(dcounter)=end;
    end;
    if next_start gt start_date+21 or missing(next_start) then do;
      days=60;
      if missing(drug) then do;
        drug=hold_drug;
        do i=1 to dim(adrugs);
          if (not missing(adrugs(i))) and adates(i) ge start_date then do;
            drug=catx('+',drug,adrugs(i));
            end_date=max(end_date,adates(i));
          end;
          else do;
            call missing(adrugs(i));
            call missing(adates(i));
          end;
          if (not missing(hold_drugs(i))) and hold_dates(i) ge start_date then do;
            drug=catx('+',drug,hold_drugs(i));
            end_date=max(end_date,hold_dates(i));
          end;
          else do;
            call missing(hold_drugs(i));
            call missing(hold_dates(i));
          end;
        end;
        call missing(of hold_drugs(*));
        call missing(of hold_dates(*));
        call missing(hold_drug);
      end;
    end;
    else days=21;
  end;
  
  
  
  /* if not first record in lot and still within 21 day period check to see if drug in drug list */
  else if days eq 21 then do;
    if drug_type eq 'Core' then do;
      if not findw(drug,strip(drug_name)) then do;
        drug=catx('+',drug,drug_name);
        dcounter+1;
        adrugs(dcounter)=drug_name;
        adates(dcounter)=end;
      end;
      do i=1 to dim(adrugs);
        if drug_name eq adrugs(i) and adates(i) lt start_date then do;
          adates(i)=end;
        end;
      end;
      counter+1;
      end_date=max(end_date,end);
    end;
    
    else if missing(drug) then do;
      if not findw(hold_drug,strip(drug_name)) then do;
        hold_drug=catx('+',hold_drug,drug_name);
        dcounter+1;
        hold_drugs(dcounter)=drug_name;
        hold_dates(dcounter)=end;
      end;
      do i=1 to dim(adrugs);
        if drug_name eq hold_drugs(i) and hold_dates(i) lt start_date then do;
          hold_dates(i)=end;
        end;
      end;
      end_date=max(end_date,end);
      counter+1;
    end;
 
    /* add Non_core if lot already has at least one core */
    else do;
      if not findw(drug,strip(drug_name)) then do;
        drug=catx('+',drug,drug_name);
        dcounter+1;
        adrugs(dcounter)=drug_name;
        adates(dcounter)=end;
      end;
      counter+1;
    end;

    if next_start gt start_date+21 or missing(next_start) then do;
      days=60;
      if missing(drug) then do;
        drug=hold_drug;
        do i=1 to dim(adrugs);
          if (not missing(adrugs(i))) and adates(i) ge start_date then do;
            drug=catx('+',drug,adrugs(i));
            end_date=max(end_date,adates(i));
          end;
          else do;
            call missing(adrugs(i));
            call missing(adates(i));
          end;
          if (not missing(hold_drugs(i))) and hold_dates(i) ge start_date then do;
            drug=catx('+',drug,hold_drugs(i));
            end_date=max(end_date,hold_dates(i));
          end;
          else do;
            call missing(hold_drugs(i));
            call missing(hold_dates(i));
          end;
        end;
        call missing(of hold_drugs(*));
        call missing(of hold_dates(*));
        call missing(hold_drug);
      end;
    end;
  end;

  /* within 60 day check */
  else do;
    days=60;
    if start le end_date+60 and findw(drug,strip(drug_name)) and drug_type eq 'Core' then do;
      counter+1;
      end_date=max(end,end_date);
      do i=1 to dim(adrugs);
        if adrugs(i) eq strip(drug_name) then do;
          adates(i)=max(adates(i),end);
        end;
      end;
    end;
  end;
*output;
  
  /* check to see if last.patient_id or next record indicates new lot */
  if last.patient_id or
     (counter gt 0 and
     days eq 60 and
     (next_start gt end_date+60 or
      ((not findw(drug,strip(next_drug))) and
       next_type eq 'Core')))
  then do;
    if not missing(next_start) and next_start le end_date then end_date=next_start-1;
    lot+1;
    output;
    counter=0;
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 15:25:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/376065#M90207</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-14T15:25:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the desired output data to determine treatment pattern?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/376106#M90223</link>
      <description>&lt;P&gt;While I REALLY can't spend more time on this, I did find where the code was double entering non-core drugs in the drug list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following appears to match your stated want (at least for the example you provided):&lt;/P&gt;
&lt;PRE&gt;/* last revised 14JUL2017 1:02 pm EDT*/&lt;BR /&gt;data have;
  informat patient_id $15. drug_name $30. ;
  infile cards delimiter='09'x;
  input patient_id drug_name drug_type $ (start end) (: date9.);
  format start end  date9.;
  format drug_name $30.;
  cards;
13213	Vemurafenib	Core	12AUG2014	10SEP2014
13213	Vemurafenib	Core	05SEP2014	04OCT2014
13213	Vemurafenib	Core	03OCT2014	01NOV2014
13213	Vemurafenib	Core	03NOV2014	02DEC2014
13213	Vemurafenib	Core	08DEC2014	06JAN2015
13213	Vemurafenib	Core	05JAN2015	03FEB2015
13213	Vemurafenib	Core	06FEB2015	07MAR2015
13213	Vemurafenib	Core	13MAR2015	11APR2015
13213	Vemurafenib	Core	13APR2015	12MAY2015
13213	Vemurafenib	Core	14MAY2015	12JUN2015
13213	Vemurafenib	Core	11JUN2015	10JUL2015
13213	Vemurafenib	Core	14JUL2015	12AUG2015
13213	Vemurafenib	Core	12AUG2015	10SEP2015
13213	Vemurafenib	Core	15SEP2015	14OCT2015
13213	Vemurafenib	Core	13OCT2015	11NOV2015
13213	Vemurafenib	Core	17NOV2015	14DEC2015
13213	Vemurafenib	Core	11DEC2015	07JAN2016
13213	Vemurafenib	Core	11JAN2016	07FEB2016
13213	Cobimetinib	Core	20JAN2016	16FEB2016
13213	Vemurafenib	Core	11FEB2016	09MAR2016
13213	Cobimetinib	Core	11FEB2016	09MAR2016
13213	Vemurafenib	Core	21MAR2016	17APR2016
13213	Cobimetinib	Core	21MAR2016	17APR2016
13213	Vemurafenib	Core	19APR2016	16MAY2016
13213	Cobimetinib	Core	19APR2016	16MAY2016
13213	Vemurafenib	Core	18MAY2016	14JUN2016
13213	Cobimetinib	Core	18MAY2016	14JUN2016
13213	Vemurafenib	Core	14JUN2016	11JUL2016
13213	Cobimetinib	Core	16JUN2016	13JUL2016
1124567	Dasatinib	Non_core	02JUN2014	01JUL2014
1124567	Dasatinib	Non_core	11JUL2014	09AUG2014
1124567	Dasatinib	Non_core	07AUG2014	05SEP2014
1124567	Dasatinib	Non_core	03SEP2014	02OCT2014
1414197	Interferon-Alfa-2b	Non_core	08JUN2015	05JUL2015
1414197	Interferon-Alfa-2b	Non_core	11JUL2015	07AUG2015
1414197	Interferon-Alfa-2b	Non_core	01AUG2015	28AUG2015
1414197	Interferon-Alfa-2b	Non_core	21AUG2015	17SEP2015
1414197	Interferon-Alfa-2b	Non_core	19SEP2015	16OCT2015
1414197	Interferon-Alfa-2b	Non_core	26OCT2015	22NOV2015
1414197	Interferon-Alfa-2b	Non_core	16NOV2015	16DEC2015
1414197	Interferon-Alfa-2b	Non_core	14DEC2015	13JAN2016
1414197	Interferon-Alfa-2b	Non_core	08JAN2016	07FEB2016
1414197	Interferon-Alfa-2b	Non_core	09FEB2016	10MAR2016
1414197	Interferon-Alfa-2b	Non_core	10MAR2016	09APR2016
1414197	Interferon-Alfa-2b	Non_core	05APR2016	05MAY2016
1414197	Interferon-Alfa-2b	Non_core	10MAY2016	30MAY2016
746461	PegInterferon-Alfa-2b	Non_core	6Aug2014	2Sep2014
746461	PegInterferon-Alfa-2b	Non_core	2Sep2014	29Sep2014
746461	PegInterferon-Alfa-2b	Non_core	8Oct2014	4Nov2014
746461	PegInterferon-Alfa-2b	Non_core	5Dec2014	1Jan2015
746461	PegInterferon-Alfa-2b	Non_core	8Jan2015	6Feb2015
746461	PegInterferon-Alfa-2b	Non_core	6Feb2015	5Mar2015
746461	Ipilimumab	Core	3Mar2015	23Mar2015
746461	Temozolomide	Core	24Jun2016	21Jul2016
;

data want
 (keep=patient_id drug start_date end_date lot)
 ;
  set have;
  by patient_id notsorted;
  format start_date end_date date9.;

  /* look ahead at next record */
  set have ( firstobs = 2 keep = start drug_type drug_name 
              rename = (start = next_start drug_type=next_type drug_name=next_drug) )
      have (      obs = 1 drop = _all_ );
  next_start = ifn(last.patient_id, (.), next_start );
  next_type = ifc(last.patient_id, (.), next_type );
  next_drug = ifc(last.patient_id, (.), next_drug );
 
  /* set length of drug to be wide enough to fix all drugs */
  length drug $1000.;
  length hold_drug $1000.;
  array adrugs(100) $ 30 adrug1-adrug100;
  array adates(100) adate1-adate100;

  array hold_drugs(100) $ 30  hold_drug1-hold_drug100;
  array hold_dates(100) hold_date1-hold_date100;

 format adate1-adate20 date9.;
  retain start_date end_date drug days adrug: adate: hold_drug: hold_date:;
    
  /* initialize variables for first record within a given lot */
  if first.patient_id or counter eq 0 then do;
    if first.patient_id then do;
      lot=0;
      call missing (of adrugs(*));
      call missing (of adates(*));
      call missing (of hold_drugs(*));
      call missing (of hold_dates(*));
      dcounter=0;
    end;
    start_date=start;
    end_date=end;
    counter=1;
    drug='';
    hold_drug='';
          
    if drug_type eq 'Core' then do;
      drug=drug_name;
      dcounter+1;
      adrugs(dcounter)=drug_name;
      adates(dcounter)=end;
      do i=1 to dim(adrugs);
        if (not missing(adrugs(i))) and adates(i) ge start_date then do;
          if adrugs(i) ne strip(drug_name) then do;
            drug=catx('+',drug,adrugs(i));
            end_date=max(end_date,adates(i));
          end;
        end;
        else do;
          call missing(adrugs(i));
          call missing(adates(i));
        end;
      end;
    end;
    else do;
      call missing (of hold_drugs(*));
      call missing (of hold_dates(*));
      hold_drug=drug_name;
      dcounter+1;
      hold_drugs(dcounter)=drug_name;
      hold_dates(dcounter)=end;
    end;
    if next_start gt start_date+21 or missing(next_start) then do;
      days=60;
      if missing(drug) then do;
        drug=hold_drug;
        do i=1 to dim(adrugs);
          if (not missing(adrugs(i))) and adates(i) ge start_date then do;
            if strip(drug_name) ne adrugs(i) then drug=catx('+',drug,adrugs(i));
            end_date=max(end_date,adates(i));
          end;
          else do;
            call missing(adrugs(i));
            call missing(adates(i));
          end;
          if (not missing(hold_drugs(i))) and hold_dates(i) ge start_date then do;
            if strip(drug_name) ne hold_drugs(i) thend rug=catx('+',drug,hold_drugs(i));
            end_date=max(end_date,hold_dates(i));
          end;
          else do;
            call missing(hold_drugs(i));
            call missing(hold_dates(i));
          end;
        end;
        call missing(of hold_drugs(*));
        call missing(of hold_dates(*));
        call missing(hold_drug);
      end;
    end;
    else days=21;
  end;
  
  
  
  /* if not first record in lot and still within 21 day period check to see if drug in drug list */
  else if days eq 21 then do;
    if drug_type eq 'Core' then do;
      if not findw(drug,strip(drug_name)) then do;
        drug=catx('+',drug,drug_name);
        dcounter+1;
        adrugs(dcounter)=drug_name;
        adates(dcounter)=end;
      end;
      do i=1 to dim(adrugs);
        if drug_name eq adrugs(i) and adates(i) lt start_date then do;
          adates(i)=end;
        end;
      end;
      counter+1;
      end_date=max(end_date,end);
    end;
    
    else if missing(drug) then do;
      if not findw(hold_drug,strip(drug_name)) then do;
        hold_drug=catx('+',hold_drug,drug_name);
        dcounter+1;
        hold_drugs(dcounter)=drug_name;
        hold_dates(dcounter)=end;
      end;
      do i=1 to dim(adrugs);
        if drug_name eq hold_drugs(i) and hold_dates(i) lt /*start_date*/ end then do;
          hold_dates(i)=end;
        end;
      end;
      end_date=max(end_date,end);
      counter+1;
    end;
 
    /* add Non_core if lot already has at least one core */
    else do;
      if not findw(drug,strip(drug_name)) then do;
        drug=catx('+',drug,drug_name);
        dcounter+1;
        adrugs(dcounter)=drug_name;
        adates(dcounter)=end;
      end;
      counter+1;
    end;

    if next_start gt start_date+21 or missing(next_start) then do;
      days=60;
      if missing(drug) then do;
        drug=hold_drug;
        do i=1 to dim(adrugs);
          if (not missing(adrugs(i))) and adates(i) ge start_date then do;
/*             drug=catx('+',drug,adrugs(i)); */
            end_date=max(end_date,adates(i));
          end;
          else do;
            call missing(adrugs(i));
            call missing(adates(i));
          end;
          if (not missing(hold_drugs(i))) and hold_dates(i) ge start_date then do;
/*             drug=catx('+',drug,hold_drugs(i)); */
            end_date=max(end_date,hold_dates(i));
          end;
          else do;
            call missing(hold_drugs(i));
            call missing(hold_dates(i));
          end;
        end;
        call missing(of hold_drugs(*));
        call missing(of hold_dates(*));
        call missing(hold_drug);
      end;
    end;
  end;

  /* within 60 day check */
  else do;
    days=60;
    if start le end_date+60 and findw(drug,strip(drug_name)) /*and drug_type eq 'Core'*/ then do;
      counter+1;
      end_date=max(end,end_date);
      do i=1 to dim(adrugs);
        if adrugs(i) eq strip(drug_name) then do;
          adates(i)=max(adates(i),end);
        end;
      end;
    end;
  end;
*output;
  
  /* check to see if last.patient_id or next record indicates new lot */
  if last.patient_id or
     (counter gt 0 and
     days eq 60 and
     (next_start gt end_date+60 or
      ((not findw(drug,strip(next_drug))) and
       next_type eq 'Core')))
  then do;
    if not missing(next_start) and next_start le end_date then end_date=next_start-1;
    lot+1;
    output;
    counter=0;
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 17:03:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/376106#M90223</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-14T17:03:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the desired output data to determine treatment pattern?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/376377#M90349</link>
      <description>&lt;P&gt;Sir,thanks a lot for this help.I am now trying to fix where it does not match with the original result.I will post if I face any challenge.&lt;/P&gt;</description>
      <pubDate>Sun, 16 Jul 2017 20:58:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/376377#M90349</guid>
      <dc:creator>ani_89</dc:creator>
      <dc:date>2017-07-16T20:58:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the desired output data to determine treatment pattern?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/377949#M90791</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sir ,I have fixed all the issues and logic almost.The below are the cases where I tried hard but did not resolve the problem.If you can look into these once that would be a great help for me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data have;
length patient_id $15. drug_name $50. ;
input patient_id (drug_name drug_type) ($) (start end) (: date11.);
  format start end  date9.;
  cards;
14526897	Interferon_Alfa_2b	Non_core	11-Aug-14	11-Aug-14
14526897	Interferon_Alfa_2b	Non_core	12-Aug-14	12-Aug-14
14526897	Interferon_Alfa_2b	Non_core	13-Aug-14	13-Aug-14
14526897	Interferon_Alfa_2b	Non_core	14-Aug-14	14-Aug-14
14526897	Interferon_Alfa_2b	Non_core	15-Aug-14	15-Aug-14
14526897	Interferon_Alfa_2b	Non_core	18-Aug-14	18-Aug-14
14526897	Interferon_Alfa_2b	Non_core	19-Aug-14	19-Aug-14
14526897	Interferon_Alfa_2b	Non_core	20-Aug-14	20-Aug-14
14526897	Interferon_Alfa_2b	Non_core	21-Aug-14	21-Aug-14
14526897	Interferon_Alfa_2b	Non_core	22-Aug-14	22-Aug-14
14526897	Interferon_Alfa_2b	Non_core	25-Aug-14	25-Aug-14
14526897	Interferon_Alfa_2b	Non_core	26-Aug-14	26-Aug-14
14526897	Interferon_Alfa_2b	Non_core	27-Aug-14	27-Aug-14
14526897	Interferon_Alfa_2b	Non_core	28-Aug-14	28-Aug-14
14526897	Interferon_Alfa_2b	Non_core	2-Sep-14	2-Sep-14
14526897	Interferon_Alfa_2b	Non_core	3-Sep-14	3-Sep-14
14526897	Interferon_Alfa_2b	Non_core	3-Sep-14	30-Sep-14
14526897	Interferon_Alfa_2b	Non_core	4-Sep-14	4-Sep-14
14526897	Interferon_Alfa_2b	Non_core	5-Sep-14	5-Sep-14
14526897	Interferon_Alfa_2b	Non_core	8-Sep-14	8-Sep-14
14526897	Interferon_Alfa_2b	Non_core	9-Sep-14	9-Sep-14
14526897	Interferon_Alfa_2b	Non_core	13-Nov-14	10-Dec-14
14526897	Interferon_Alfa_2b	Non_core	23-Dec-14	19-Jan-15
14526897	Interferon_Alfa_2b	Non_core	9-Jan-15	5-Feb-15
14526897	Interferon_Alfa_2b	Non_core	27-Feb-15	26-Mar-15
14526897	Interferon_Alfa_2b	Non_core	17-Jun-15	14-Jul-15
897452634	Cisplatin	Non_core	19-Jan-16	19-Jan-16
897452634	Dacarbazine	Non_core	19-Jan-16	19-Jan-16
897452634	Ipilimumab	Core	19-Jan-16	19-Jan-16
897452634	Vinblastine	Non_core	19-Jan-16	19-Jan-16
897452634	Cisplatin	Non_core	20-Jan-16	20-Jan-16
897452634	Vinblastine	Non_core	20-Jan-16	20-Jan-16
897452634	Cisplatin	Non_core	21-Jan-16	21-Jan-16
897452634	Vinblastine	Non_core	21-Jan-16	21-Jan-16
897452634	Vinblastine	Non_core	22-Jan-16	22-Jan-16
897452634	Cisplatin	Non_core	9-Feb-16	9-Feb-16
897452634	Dacarbazine	Non_core	9-Feb-16	9-Feb-16
897452634	Ipilimumab	Core	9-Feb-16	9-Feb-16
897452634	Vinblastine	Non_core	9-Feb-16	9-Feb-16
897452634	Cisplatin	Non_core	10-Feb-16	10-Feb-16
897452634	Vinblastine	Non_core	10-Feb-16	10-Feb-16
897452634	Cisplatin	Non_core	11-Feb-16	11-Feb-16
897452634	Vinblastine	Non_core	11-Feb-16	11-Feb-16
897452634	Vinblastine	Non_core	12-Feb-16	12-Feb-16
897452634	Cisplatin	Non_core	1-Mar-16	1-Mar-16
897452634	Dacarbazine	Non_core	1-Mar-16	1-Mar-16
897452634	Ipilimumab	Core	1-Mar-16	1-Mar-16
897452634	Vinblastine	Non_core	1-Mar-16	1-Mar-16
897452634	Cisplatin	Non_core	2-Mar-16	2-Mar-16
897452634	Vinblastine	Non_core	2-Mar-16	2-Mar-16
897452634	Cisplatin	Non_core	3-Mar-16	3-Mar-16
897452634	Vinblastine	Non_core	3-Mar-16	3-Mar-16
897452634	Cisplatin	Non_core	22-Mar-16	22-Mar-16
897452634	Dacarbazine	Non_core	22-Mar-16	22-Mar-16
897452634	Ipilimumab	Core	22-Mar-16	22-Mar-16
897452634	Vinblastine	Non_core	22-Mar-16	22-Mar-16
897452634	Cisplatin	Non_core	23-Mar-16	23-Mar-16
897452634	Vinblastine	Non_core	23-Mar-16	23-Mar-16
897452634	Cisplatin	Non_core	24-Mar-16	24-Mar-16
897452634	Vinblastine	Non_core	24-Mar-16	24-Mar-16
587956	Ipilimumab	Core	31-May-13	22-Aug-13
587956	Ipilimumab	Core	3-Jun-13	3-Jun-13
587956	Dacarbazine	Non_core	4-Jun-13	4-Jun-13
587956	Ipilimumab	Core	4-Jun-13	4-Jun-13
587956	Ipilimumab	Core	14-Jun-13	14-Jun-13
587956	Dacarbazine	Non_core	1-Jul-13	1-Jul-13
587956	Ipilimumab	Core	1-Jul-13	1-Jul-13
587956	Ipilimumab	Core	3-Jul-13	3-Jul-13
587956	Dacarbazine	Non_core	30-Jul-13	30-Jul-13
587956	Ipilimumab	Core	30-Jul-13	30-Jul-13
587956	Dacarbazine	Non_core	27-Aug-13	27-Aug-13
587956	Ipilimumab	Core	27-Aug-13	27-Aug-13
587956	Ipilimumab	Core	14-Oct-13	14-Oct-13
587956	Dacarbazine	Non_core	15-Oct-13	15-Oct-13
9874526	Vemurafenib	Core	9-May-13	7-Jun-13
9874526	Vemurafenib	Core	11-Jun-13	10-Jul-13
9874526	Vemurafenib	Core	13-Jun-13	13-Jun-13
9874526	Vemurafenib	Core	11-Jul-13	11-Jul-13
9874526	Vemurafenib	Core	13-Jul-13	11-Aug-13
9874526	Vemurafenib	Core	13-Aug-13	13-Aug-13
9874526	Dabrafenib	Core	19-Aug-13	17-Sep-13
9874526	Trametinib_Dimethyl_Sulfoxide	Core	19-Aug-13	17-Sep-13
9874526	Trametinib_Dimethyl_Sulfoxide	Core	10-Sep-13	10-Sep-13
9874526	Trametinib_Dimethyl_Sulfoxide	Core	18-Sep-13	17-Oct-13
9874526	Dabrafenib	Core	23-Sep-13	22-Oct-13
9874526	Dabrafenib	Core	8-Oct-13	8-Oct-13
9874526	Dabrafenib	Core	21-Oct-13	19-Nov-13
9874526	Trametinib_Dimethyl_Sulfoxide	Core	21-Oct-13	19-Nov-13
9874526	Trametinib_Dimethyl_Sulfoxide	Core	6-Nov-13	6-Nov-13
9874526	Dabrafenib	Core	18-Nov-13	17-Dec-13
9874526	Trametinib_Dimethyl_Sulfoxide	Core	18-Nov-13	17-Dec-13
9874526	Trametinib_Dimethyl_Sulfoxide	Core	5-Dec-13	5-Dec-13
9874526	Dabrafenib	Core	23-Dec-13	21-Jan-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	23-Dec-13	21-Jan-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	2-Jan-14	2-Jan-14
9874526	Dabrafenib	Core	20-Jan-14	18-Feb-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	20-Jan-14	18-Feb-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	11-Feb-14	12-Mar-14
9874526	Dabrafenib	Core	18-Feb-14	19-Mar-14
9874526	Dabrafenib	Core	25-Feb-14	25-Feb-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	1-Apr-14	30-Apr-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	6-May-14	6-May-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	7-May-14	5-Jun-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	3-Jun-14	3-Jun-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	6-Jun-14	5-Jul-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	8-Jul-14	6-Aug-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	17-Jul-14	17-Jul-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	7-Aug-14	5-Sep-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	20-Aug-14	20-Aug-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	3-Sep-14	2-Oct-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	18-Sep-14	18-Sep-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	2-Oct-14	31-Oct-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	16-Oct-14	16-Oct-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	4-Nov-14	3-Dec-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	12-Nov-14	12-Nov-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	15-Dec-14	13-Jan-15
9874526	Trametinib_Dimethyl_Sulfoxide	Core	16-Dec-14	16-Dec-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	13-Jan-15	11-Feb-15
9874526	Trametinib_Dimethyl_Sulfoxide	Core	10-Feb-15	10-Feb-15
9874526	Trametinib_Dimethyl_Sulfoxide	Core	19-Feb-15	20-Mar-15
9874526	Trametinib_Dimethyl_Sulfoxide	Core	19-Mar-15	19-Mar-15
9874526	Trametinib_Dimethyl_Sulfoxide	Core	14-Apr-15	13-May-15
9874526	Trametinib_Dimethyl_Sulfoxide	Core	23-Apr-15	23-Apr-15
9874526	Trametinib_Dimethyl_Sulfoxide	Core	14-May-15	12-Jun-15
9874526	Trametinib_Dimethyl_Sulfoxide	Core	11-Jun-15	10-Jul-15
9874526	Trametinib_Dimethyl_Sulfoxide	Core	30-Jun-15	30-Jun-15
9874526	Trametinib_Dimethyl_Sulfoxide	Core	28-Jul-15	28-Jul-15
9874526	Trametinib_Dimethyl_Sulfoxide	Core	29-Jul-15	27-Aug-15
9874526	Trametinib_Dimethyl_Sulfoxide	Core	26-Aug-15	26-Aug-15
9874526	Trametinib_Dimethyl_Sulfoxide	Core	2-Sep-15	1-Oct-15
9874526	Vemurafenib	Core	2-Sep-15	1-Oct-15
9874526	Vemurafenib	Core	24-Sep-15	24-Sep-15
9874526	Trametinib_Dimethyl_Sulfoxide	Core	30-Sep-15	29-Oct-15
9874526	Vemurafenib	Core	23-Oct-15	21-Nov-15
9874526	Cobimetinib	Core	4-Dec-15	9-Jan-16
9874526	Cobimetinib	Core	23-Dec-15	23-Dec-15
9874526	Cobimetinib	Core	4-Jan-16	9-Feb-16
9874526	Ipilimumab	Core	3-Feb-16	3-Feb-16
9874526	Nivolumab	Core	3-Feb-16	3-Feb-16
874512399	Dabrafenib	Core	25-Apr-14	24-May-14
874512399	Trametinib_Dimethyl_Sulfoxide	Core	29-Apr-14	28-May-14
874512399	Trametinib_Dimethyl_Sulfoxide	Core	30-May-14	28-Jun-14
874512399	Dabrafenib	Core	2-Jun-14	1-Jul-14
874512399	Trametinib_Dimethyl_Sulfoxide	Core	4-Aug-14	2-Sep-14
874512399	Dabrafenib	Core	5-Aug-14	3-Sep-14
874512399	Dabrafenib	Core	16-Sep-14	15-Oct-14
874512399	Trametinib_Dimethyl_Sulfoxide	Core	16-Sep-14	15-Oct-14
874512399	Trametinib_Dimethyl_Sulfoxide	Core	11-Nov-14	11-Nov-14
874512399	Trametinib_Dimethyl_Sulfoxide	Core	1-Dec-14	1-Dec-14
874512399	Trametinib_Dimethyl_Sulfoxide	Core	21-Dec-14	21-Dec-14
874512399	Trametinib_Dimethyl_Sulfoxide	Core	22-Dec-14	22-Dec-14
874512399	Trametinib_Dimethyl_Sulfoxide	Core	21-Jan-15	21-Jan-15
874512399	Trametinib_Dimethyl_Sulfoxide	Core	16-Apr-15	16-Apr-15
874512399	Bevacizumab	Non_core	1-May-15	1-May-15
874512399	Bevacizumab	Non_core	18-May-15	18-May-15
874512399	Bevacizumab	Non_core	2-Jun-15	2-Jun-15
874512399	Bevacizumab	Non_core	16-Jun-15	16-Jun-15
874512399	Bevacizumab	Non_core	8-Jul-15	8-Jul-15
874512399	Bevacizumab	Non_core	22-Jul-15	22-Jul-15
874512399	Bevacizumab	Non_core	5-Aug-15	5-Aug-15
874512399	Bevacizumab	Non_core	25-Aug-15	25-Aug-15
874512399	Bevacizumab	Non_core	17-Sep-15	17-Sep-15
874512399	Bevacizumab	Non_core	1-Oct-15	1-Oct-15
874512399	Bevacizumab	Non_core	14-Oct-15	14-Oct-15
874512399	Bevacizumab	Non_core	27-Oct-15	27-Oct-15
874512399	Bevacizumab	Non_core	13-Nov-15	13-Nov-15
874512399	Bevacizumab	Non_core	4-Dec-15	4-Dec-15
874512399	Bevacizumab	Non_core	24-Dec-15	24-Dec-15
874512399	Bevacizumab	Non_core	15-Jan-16	15-Jan-16
874512399	Bevacizumab	Non_core	5-Feb-16	5-Feb-16
874512399	Bevacizumab	Non_core	26-Feb-16	26-Feb-16
874512399	Bevacizumab	Non_core	18-Mar-16	18-Mar-16
874512399	Bevacizumab	Non_core	8-Apr-16	8-Apr-16
874512399	Pembrolizumab	Core	8-Apr-16	8-Apr-16
74521369845	Cisplatin	Non_core	29-Jul-14	29-Jul-14
74521369845	Dacarbazine	Non_core	29-Jul-14	29-Jul-14
74521369845	Vinblastine	Non_core	29-Jul-14	29-Jul-14
74521369845	Cisplatin	Non_core	30-Jul-14	30-Jul-14
74521369845	Vinblastine	Non_core	30-Jul-14	30-Jul-14
74521369845	Cisplatin	Non_core	31-Jul-14	31-Jul-14
74521369845	Vinblastine	Non_core	31-Jul-14	31-Jul-14
74521369845	Cisplatin	Non_core	26-Aug-14	26-Aug-14
74521369845	Dacarbazine	Non_core	26-Aug-14	26-Aug-14
74521369845	Ipilimumab	Core	26-Aug-14	26-Aug-14
74521369845	Vinblastine	Non_core	26-Aug-14	26-Aug-14
74521369845	Cisplatin	Non_core	27-Aug-14	27-Aug-14
74521369845	Vinblastine	Non_core	27-Aug-14	27-Aug-14
74521369845	Cisplatin	Non_core	28-Aug-14	28-Aug-14
74521369845	Vinblastine	Non_core	28-Aug-14	28-Aug-14
74521369845	Cisplatin	Non_core	16-Sep-14	16-Sep-14
74521369845	Dacarbazine	Non_core	16-Sep-14	16-Sep-14
74521369845	Ipilimumab	Core	16-Sep-14	16-Sep-14
74521369845	Vinblastine	Non_core	16-Sep-14	16-Sep-14
74521369845	Cisplatin	Non_core	17-Sep-14	17-Sep-14
74521369845	Vinblastine	Non_core	17-Sep-14	17-Sep-14
74521369845	Cisplatin	Non_core	18-Sep-14	18-Sep-14
74521369845	Vinblastine	Non_core	18-Sep-14	18-Sep-14
74521369845	Vinblastine	Non_core	19-Sep-14	19-Sep-14
74521369845	Cisplatin	Non_core	7-Oct-14	7-Oct-14
74521369845	Dacarbazine	Non_core	7-Oct-14	7-Oct-14
74521369845	Ipilimumab	Core	7-Oct-14	7-Oct-14
74521369845	Vinblastine	Non_core	7-Oct-14	7-Oct-14
74521369845	Cisplatin	Non_core	8-Oct-14	8-Oct-14
74521369845	Vinblastine	Non_core	8-Oct-14	8-Oct-14
74521369845	Cisplatin	Non_core	9-Oct-14	9-Oct-14
74521369845	Vinblastine	Non_core	9-Oct-14	9-Oct-14
74521369845	Vinblastine	Non_core	10-Oct-14	10-Oct-14
74521369845	Cisplatin	Non_core	28-Oct-14	28-Oct-14
74521369845	Dacarbazine	Non_core	28-Oct-14	28-Oct-14
74521369845	Vinblastine	Non_core	28-Oct-14	28-Oct-14
74521369845	Cisplatin	Non_core	29-Oct-14	29-Oct-14
74521369845	Vinblastine	Non_core	29-Oct-14	29-Oct-14
74521369845	Cisplatin	Non_core	30-Oct-14	30-Oct-14
74521369845	Vinblastine	Non_core	30-Oct-14	30-Oct-14
74521369845	Cisplatin	Non_core	2-Dec-14	2-Dec-14
74521369845	Dacarbazine	Non_core	2-Dec-14	2-Dec-14
74521369845	Vinblastine	Non_core	2-Dec-14	2-Dec-14
74521369845	Cisplatin	Non_core	3-Dec-14	3-Dec-14
74521369845	Vinblastine	Non_core	3-Dec-14	3-Dec-14
74521369845	Cisplatin	Non_core	4-Dec-14	4-Dec-14
74521369845	Vinblastine	Non_core	4-Dec-14	4-Dec-14
4526789	Interleukin-2	Core	26-Oct-15	31-Oct-15
4526789	Interleukin-2	Core	27-Oct-15	27-Oct-15
4526789	Interleukin-2	Core	28-Oct-15	28-Oct-15
4526789	Interleukin-2	Core	29-Oct-15	29-Oct-15
4526789	Interleukin-2	Core	30-Oct-15	30-Oct-15
4526789	Interleukin-2	Core	31-Oct-15	31-Oct-15
4526789	Interferon_Alfa_2b	Non_core	2-Nov-15	29-Nov-15
4526789	Interferon_Alfa_2b	Non_core	16-Nov-15	20-Nov-15
4526789	Interferon_Alfa_2b	Non_core	17-Nov-15	17-Nov-15
4526789	Interferon_Alfa_2b	Non_core	18-Nov-15	18-Nov-15
4526789	Interferon_Alfa_2b	Non_core	19-Nov-15	19-Nov-15
4526789	Interferon_Alfa_2b	Non_core	20-Nov-15	20-Nov-15
4526789	Interferon_Alfa_2b	Non_core	7-Dec-15	3-Jan-16
4526789	Interleukin-2	Core	7-Dec-15	11-Dec-15
4526789	Interleukin-2	Core	8-Dec-15	8-Dec-15
4526789	Interleukin-2	Core	9-Dec-15	9-Dec-15
4526789	Interleukin-2	Core	10-Dec-15	10-Dec-15
4526789	Interleukin-2	Core	11-Dec-15	11-Dec-15
4526789	Pembrolizumab	Core	30-Mar-16	30-Mar-16
4526789	Pembrolizumab	Core	20-Apr-16	20-Apr-16
4526789	Pembrolizumab	Core	11-May-16	11-May-16
4526789	Pembrolizumab	Core	18-May-16	18-May-16
4526789	Pembrolizumab	Core	8-Jun-16	8-Jun-16
4526789	Pembrolizumab	Core	29-Jun-16	29-Jun-16
78954526	Dabrafenib	Core	25-Apr-14	24-May-14
78954526	Trametinib_Dimethyl_Sulfoxide	Core	25-Apr-14	24-May-14
78954526	Dabrafenib	Core	30-Apr-14	29-May-14
78954526	Trametinib_Dimethyl_Sulfoxide	Core	30-Apr-14	29-May-14
78954526	Dabrafenib	Core	29-May-14	27-Jun-14
78954526	Trametinib_Dimethyl_Sulfoxide	Core	29-May-14	27-Jun-14
78954526	Dabrafenib	Core	25-Jun-14	24-Jul-14
78954526	Trametinib_Dimethyl_Sulfoxide	Core	25-Jun-14	24-Jul-14
78954526	Dabrafenib	Core	18-Aug-14	16-Sep-14
78954526	Trametinib_Dimethyl_Sulfoxide	Core	18-Aug-14	16-Sep-14
78954526	Dabrafenib	Core	15-Sep-14	14-Oct-14
78954526	Trametinib_Dimethyl_Sulfoxide	Core	15-Sep-14	14-Oct-14
78954526	Ipilimumab	Core	9-Oct-14	9-Oct-14
8745120369	Dabrafenib	Core	18-Aug-14	16-Sep-14
8745120369	Dabrafenib	Core	20-Aug-14	18-Sep-14
8745120369	Trametinib_Dimethyl_Sulfoxide	Core	26-Aug-14	24-Sep-14
8745120369	Trametinib_Dimethyl_Sulfoxide	Core	23-Sep-14	21-Dec-14
8745120369	Dabrafenib	Core	17-Oct-14	14-Jan-15
8745120369	Ipilimumab	Core	22-Dec-14	22-Dec-14
;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For patient id 14526897 - a non core drug Interferon Alfa-2b starts on 11aug2014 and applying 21 days we get lot 1 ends on 9 sep2014.there is no drug use or a new core drug in 60 dyas period after finishing of lot 1 .so lot 2 begins on 13nov2014 apply the same above rule we get lot 2 ends on 26mar2014.And so on.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;For patient id 897452634- Non core drug Cisplatin starts on 19jan2016 and apply 21 days and 60 days criteria we get end of latest use core drug is 22mar2016 so lot end here .As per the rule if there is core and non core drug in the lot the end date would be end date of latest use core drug not the end date of of laest use non core drug after apply 21 days and 60 days criteria.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;For patient id 587956 - a core drug Ipilumab starts on 31may2013 .applying 21 days and 60 days criteria ,we get end date of latest use core drug is 14oct2015 as lot 1 contains both core and noncore drugs.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;For patient id 9874526 - Lot 4 end on 2feb2015 as a new core drug other than lot 5 starts on 3rd feb.As per the overlapping rule if a core drug from previous lot continues after start of current regiemn and it will again start on anytime within 21 days or 60 dyas then this core drug will be added in the current regimen.If a core drug from previous regimen continues after starting of current regimen but it does not start again in 21 or 60 days periods of current regimen then overlapping rule will not be applied.overlapping rule is not aplied for non core drugs.In this current patient id as the non core drug Combimetinib from lot 4 continues after start of lot 4.but as it non core we will not add this in lot 5 but currently it is being added which should not be the case.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;For patient id 874512399 - Core drug Dabrafenib starts on 25 april and within 21 days Trametinib Dimethyl Sulfoxide starts and latest use of the core drug is 28may2014. now applying 60 days criteria we get lot 1 ends on 21jan 2015.As per the rule of new lot start ethier there shold be no use of drug within 60 days or there is any new core drug starts within 60 days.Here from end date of lot1 is 21jan2015 with a blank period of more than 60 days.So lot2 starts on 16apr2015 .after applying 21 days criteris we get Bevacizumab starts within 21 days and after applying 60 days criteria there is no core drug found .so lot 2 ends on 16apr2015.To start of lot 3 ,there should be gap of blank 60 days with no drug use or a new core drug other than previous lot should be there .So applying this rule we get Bevacizumab starts on 16june2015 and apply 21 and 60 days criteria ,we get lot 3 ends on 7apr2016(1 day prior to new core core drug ) as a new core drug other than lot3 starts on 8apr2016.Now lot4 begins and apllying rthe same rule we get it ends on 8apr2016.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;For patient id 74521369845 - A non core drugs starts on 29july2014 after apllying 21 and 60 days criteria we found a new core drug Ipilumab starts on 26aug20114 so lot 1 ends here.lot 2 starts on 26aug2014.after apllying 21 days we found a non core drug from previous lot contines after or on start of lot 2 and gian starts on within 60 days but we should not include it in lot as for non core drug the overlapping rules are not applied.and after applying 60 days criteria we get end date of latest use core drug is 7oct2014 so lot2 ends here.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;For patient id 4526789 - a core drug interlukin-2 starts on 26-oct2015 .after applying 21 days and 60 days criteria ,we end date of latest use core drus is 11 dec2015 as lot 1 is core plus non coreregimen.again as there is no drug in 60 dys period or no new core drug available,so lot 2 starts on 30mar2016 ..and apply the all rule we get lot 2 ends on 29jun2016.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;For patient id 78954526 - a core drug dabrafinib starts on 30apr14 .after applying 21 days and 60 criteria we get lot 1 ends on 8 th october as a new core drug other than from the lot 1 starts on 9oct.As per the overlapping rule if a core drug from previous lot continues after start of current regiemn and it will again start on anytime within 21 days or 60 dyas then this core drug will be added in the current regimen.If a core drug from previous regimen continues after starting of current regimen but it does not start again in 21 or 60 days periods of current regimen then overlapping rule will not be applied.Although core drug Dabranib and Trametinib continues after start of lot 2 but any of them did not start again anytime within 21 or 60 days.so it will not be included in lot 2 .but currently it is being included.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For patient id 8745120369 - the same thing as patinet id 78954526&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data i want -&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;patien_id &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drug &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; start &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;14526897 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Interferon Alfa-2b &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;11AUG2014 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;09SEP2014&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;14526897 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Interferon_Alfa_2b &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 13NOV2014 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;26MAR2015&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;14526897 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Interferon_Alfa_2b &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 17JUN2015 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 14JUL2015&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;897452634 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Cisplatin+Dacarbazine+Ipilimumab+Vinblastine &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;19JAN2016 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 22MAR2016&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;587956 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Dacarbazine+Ipilimumab &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 31MAY2013 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;14OCT2013&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;9874526 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Vemurafenib &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 09MAY2013 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;13AUG2013&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;9874526 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Dabrafenib+Trametinib Dimethyl Sulfoxide &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 19AUG2013 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01SEP2015&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;9874526 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Trametinib Dimethyl Sulfoxide+Vemurafenib &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 02SEP2015 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 21NOV2015&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;9874526 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Cobimetinib &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;04DEC2015 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 02FEB2016&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;9874526 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Ipilimumab+Nivolumab &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;03FEB2016 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 03FEB2016&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;874512399 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dabrafenib+Trametinib Dimethyl Sulfoxide &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 25APR2014 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 21JAN2015&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;874512399 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Bevacizumab+Trametinib Dimethyl Sulfoxide &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;16APR2015 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 16APR2015&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;874512399 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Bevacizumab &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;16JUN2015 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;07APR2016&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;874512399 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Pembrolizumab + Bevacizumab &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 08APR2016 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;08APR2016&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;74521369845 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Cisplatin+Dacarbazine+Vinblastine &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;29JUL2014 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;25AUG2014&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;74521369845 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Cisplatin+Ipilimumab+Vinblastine &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 26AUG2014 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 07OCT2014&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;4526789 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Interferon Alfa-2b+Interleukin-2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 26OCT2015 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;11DEC2015&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;4526789 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Pembrolizumab &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;30MAR2016 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;29JUN2016&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;78954526 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dabrafenib+Trametinib Dimethyl Sulfoxide &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;25APR2014 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 08OCT2014&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;78954526 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Ipilimumab &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;09OCT2014 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 09OCT2014&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;8745120369 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dabrafenib+Trametinib Dimethyl Sulfoxide &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;18AUG2014 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 21DEC2014&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;8745120369 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Ipilimumab &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 22DEC2014 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;22DEC2014&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;The result I am currently getting -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;patien_id &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drug &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;start &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Lot&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;14526897 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Interferon_Alfa_2b &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;11-Aug-14 &amp;nbsp; &amp;nbsp; &amp;nbsp;26-Mar-15 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;14526897 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Interferon_Alfa_2b &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;17-Jun-15 &amp;nbsp; &amp;nbsp; &amp;nbsp;14-Jul-15 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;897452634 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Ipilimumab+Vinblastine+Cisplatin+Dacarbazine &amp;nbsp; 19-Jan-16 &amp;nbsp; &amp;nbsp; &amp;nbsp;24-Mar-16 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;587956 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Ipilimumab+Dacarbazine &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;31-May-13 &amp;nbsp; &amp;nbsp;15-Oct-13 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;9874526 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Vemurafenib &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9-May-13 &amp;nbsp; &amp;nbsp; &amp;nbsp;13-Aug-13 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;9874526 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Dabrafenib+Trametinib Dimethyl Sulfoxide &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;19-Aug-13 &amp;nbsp; &amp;nbsp; 1-Sep-15 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;9874526 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Vemurafenib+Trametinib Dimethyl Sulfoxide &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2-Sep-15 &amp;nbsp; &amp;nbsp; &amp;nbsp; 21-Nov-15 &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;9874526 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Cobimetinib &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4-Dec-15 &amp;nbsp; &amp;nbsp; &amp;nbsp; 2-Feb-16 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;9874526 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Ipilimumab+Cobimetinib+Nivolumab &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3-Feb-16 &amp;nbsp; &amp;nbsp; &amp;nbsp; 9-Feb-16 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;874512399 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dabrafenib+Trametinib Dimethyl Sulfoxide &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;25-Apr-14 &amp;nbsp; &amp;nbsp; &amp;nbsp;21-Jan-15 &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;874512399 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Trametinib Dimethyl Sulfoxide+Bevacizumab &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 16-Apr-15 &amp;nbsp; &amp;nbsp; &amp;nbsp; 7-Apr-16 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;874512399 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Pembrolizumab+Bevacizumab &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8-Apr-16 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;8-Apr-16 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;74521369845 &amp;nbsp; &amp;nbsp;Cisplatin+Dacarbazine+Vinblastine &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 29-Jul-14 &amp;nbsp; &amp;nbsp; &amp;nbsp; 25-Aug-14 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;74521369845 &amp;nbsp; &amp;nbsp; Ipilimumab+Vinblastine+Cisplatin+Dacarbazine &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 26-Aug-14 &amp;nbsp; &amp;nbsp; 4-Dec-14 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;4526789 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Interleukin-2+Interferon Alfa-2b &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 26-Oct-15 &amp;nbsp; &amp;nbsp; &amp;nbsp;3-Jan-16 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;4526789 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Pembrolizumab &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;30-Mar-16 &amp;nbsp; &amp;nbsp; 29-Jun-16 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;78954526 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dabrafenib+Trametinib Dimethyl Sulfoxide &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;25-Apr-14 &amp;nbsp; &amp;nbsp; &amp;nbsp;8-Oct-14 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;78954526 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Ipilimumab+Dabrafenib+Trametinib Dimethyl Sulfoxide &amp;nbsp; 9-Oct-14 &amp;nbsp; &amp;nbsp; 14-Oct-14 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;8745120369 &amp;nbsp; &amp;nbsp; Dabrafenib+Trametinib Dimethyl Sulfoxide &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 18-Aug-14 &amp;nbsp; &amp;nbsp; 21-Dec-14 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;8745120369 &amp;nbsp; &amp;nbsp; &amp;nbsp;Ipilimumab+Dabrafenib &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 22-Dec-14 &amp;nbsp; &amp;nbsp; 14-Jan-15 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jul 2017 22:25:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/377949#M90791</guid>
      <dc:creator>ani_89</dc:creator>
      <dc:date>2017-07-20T22:25:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the desired output data to determine treatment pattern?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/377956#M90794</link>
      <description>&lt;P&gt;The code is producing some results you're not expecting because it is only implementing the rules as I understand them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;e.g. patient_id 14526897 got his/her drug again on Sep 3rd with an expiration date of 30sep14, As such, the sixty day window kept increasing un 26mar15.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for&amp;nbsp;&lt;SPAN&gt;patient_id&amp;nbsp;897452634,&amp;nbsp;Ipilimumab was the first drug counted as it was a core drug identified within the first 21 days.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;As for the ending dates, you'll have to review and understand the code to ensure that your number of days criteria are met. That is the main place where the current code might be wrong.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Art, CEO, AnalystFinder.com&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jul 2017 22:31:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/377956#M90794</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-20T22:31:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the desired output data to determine treatment pattern?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/378334#M90880</link>
      <description>&lt;P&gt;Sir,thanks for you reply .&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;patient_id 14526897 the result is correct as you told.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;But for&amp;nbsp;patient_id&amp;nbsp;897452634 ,the end date of the lot it is not correct&amp;nbsp;as it is taking the maximum&amp;nbsp;date non core drug .&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Two situations&amp;nbsp;I am not etting the correct output otherwise the code works fine for me .I need to change&amp;nbsp;something in the code to get the desired output .I tried but did not get how to fix the issues .It will be really helpful &amp;nbsp;if you can look into this issues .&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Two cases where I am missing out the right condition -&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;SPAN&gt;The overlapping rules says if there is any core drug or drugs from previous regimen continues after start of current regimen and ends after start of current and the core drugs or drug starts anytime again anytime after applying 21 days and 60 days ccriteria then the overlapping rule is applied .If core drug or core drugs from previous lot continues after start of current lot but it is not started again in 21 or 60 days then the overlapping rule will not be applicable.But currenly in our code it is considerin only the core drug continues after start of current lot but it is not considering whther it is start again within 60 days or not&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;In case of a lot contains core and non core drug the enddate should the end date of latest use of core drug .But in our code it is not considering it.&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;These two patient id is having the above two issues &amp;nbsp;.I triedto explain in details why I am not getting the correct output in the below cases.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;For patient id 245689 - A Cred drug Dabrafenib starts on 14 apr 2015 and we need to check what are the oter drugs available within 21 days of 14 apr 2015.We do not have any other drug in 21days.So lot 1 will have Dabrafenib.The intial end date would 14may 2015.But as a new core drug other than lot 1 starts before the lot 1 so lot 1 ends on 1 day prior to start of Trametinib Dimethyl Sulfoxide whiich is 5may2015.Lot 2 starts on 6 th may.Now we need to check what are the are therewhich starts in 21 days of 6 th may.We get did not any drug in 21 days so intial lot 2 will have Trametinib Dimethyl Sulfoxide and intial end date will be 4june2015..Now we need to check 60 dya from 4june2015.We get drug dabrafenib starts on 2jun2015 .Itis now a overlapping situation becasue from lot 1 dabranib actually ends date is 14 may205 which is after the start date of lot 2 and it again starts on anytime in lot 2 so dabrafenib will be included in lot 2 .end date would be the end date of latest use drug which is 24 jul 2015.But as a new core drug Nivolumab starts before 24jul2015.The end date would be the 1 day prior to the start dae of Nivolumab.So lot 2 ends on 13jul2015.Lot 3 starts on 14jul2015 with a lot intiative drug Nivolumab .Now we need tocheck drug within21 days .but we did not find any drug and so on.Althoug drug Dabrafenib and Trametinib Dimethyl Sulfoxide continues after start of lot 3 but these drugs did not start again any time within 21 or 60 days.So it willl not be considered as overlapping so i will not be included in lot 3 .So lot 3ends on 14 jul2015.But currentl in our code it is considering as overlaping case which should not be.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;For patient id 4589759 - A non core drug Carboplatin starts on 1 oct 2013.Now weneed to check what are the drugs starts with 21 dyas of start of Carboplatin.So we get Paclitaxel along with Carboplatin starts within 21 days of start of lot initiative drug Carboplatin.So lot 1 will have carboplatin and paclitaxel.Maximum end date of these drug is 21 oct 2013.Now we need to check within 60 days after 21oct2013 any drug from lot 1 are there or not .If there then enddate will update with new date .But while checking 60 days we found a core drug Temazolomide starts on 25 oct 2013.So as per the rule of new lot start,There should be a minimum 60 days gap of no drug use or any new core drug found .So lot 1 ends on 21oct2013.Lot 2 satrts on 25oct13 witha lot inititive drug Temozolomide.Now again we need to identify drugs within 21 days of 25 oct2013.We found drug Paclitaxel and carboplatin within 21 days .So lot 2 will have Temozolomide,Paclitaxel,Carboplatin.As it is a combination of core and non core drug in the lot,the end date will be the end date of the core drug Temozolomide from where we need to check 60 days criteria.As there is no core drug from previous regimen found within days ,the lot ends on 21 nov 2013.In case of current lot is (core plus non core lot) or (core only lot ) ,then we need to check if any core drugs available from initial 21 days ,then only end date will update otherwise it will be the same while checking 60 days criteria after intial 21 days criteria.For non coreonly lot,we need tocheck if there is any non core drug from initial 21 days while checking 60 dyas criteriaa then end datewill update othewise it woill be th same .So in this case temozolomde core drug did not find within 60 days again .so end date of lot will be 21 nov 2013.But in our code currently it is updating the end date to 27 jun 2014 as non core drug is found within applying 60 days criteria which should be ignored as per the rule.So lot 3 begins on 23 jun 2014 and ends on 27 jun 2014 .We are getting the wrong date at lot 3 becoz it is taking the maximum end date of non care here it should end date of core crugs in case of only core or core plus non core regimen.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Data I have -&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data have;
length patient_id $15. drug_name $50. ;
input patient_id (drug_name drug_type) ($) (start end) (: date11.);
  format start end  date9.;
  cards;
245689	Dabrafenib	Core	14-Apr-15	14-May-15
245689	Trametinib_Dimethyl_Sulfoxide	Core	6-May-15	4-Jun-15
245689	Dabrafenib	Core	2-Jun-15	1-Jul-15
245689	Trametinib_Dimethyl_Sulfoxide	Core	2-Jun-15	1-Jul-15
245689	Dabrafenib	Core	25-Jun-15	24-Jul-15
245689	Trametinib_Dimethyl_Sulfoxide	Core	25-Jun-15	24-Jul-15
245689	Nivolumab	Core	14-Jul-15	14-Jul-15
4589759	Carboplatin	Non_core	1-Oct-13	1-Oct-13
4589759	Paclitaxel	Non_core	1-Oct-13	1-Oct-13
4589759	Carboplatin	Non_core	7-Oct-13	7-Oct-13
4589759	Paclitaxel	Non_core	7-Oct-13	7-Oct-13
4589759	Carboplatin	Non_core	14-Oct-13	14-Oct-13
4589759	Paclitaxel	Non_core	14-Oct-13	14-Oct-13
4589759	Carboplatin	Non_core	21-Oct-13	21-Oct-13
4589759	Paclitaxel	Non_core	21-Oct-13	21-Oct-13
4589759	Temozolomide	Core	25-Oct-13	21-Nov-13
4589759	Paclitaxel	Non_core	30-Oct-13	30-Oct-13
4589759	Paclitaxel	Non_core	5-Nov-13	5-Nov-13
4589759	Carboplatin	Non_core	13-Nov-13	13-Nov-13
4589759	Paclitaxel	Non_core	13-Nov-13	13-Nov-13
4589759	Carboplatin	Non_core	19-Nov-13	19-Nov-13
4589759	Paclitaxel	Non_core	19-Nov-13	19-Nov-13
4589759	Carboplatin	Non_core	27-Nov-13	27-Nov-13
4589759	Paclitaxel	Non_core	27-Nov-13	27-Nov-13
4589759	Carboplatin	Non_core	4-Dec-13	4-Dec-13
4589759	Paclitaxel	Non_core	4-Dec-13	4-Dec-13
4589759	Carboplatin	Non_core	11-Dec-13	11-Dec-13
4589759	Paclitaxel	Non_core	11-Dec-13	11-Dec-13
4589759	Paclitaxel	Non_core	27-Dec-13	27-Dec-13
4589759	Paclitaxel	Non_core	23-Jun-14	27-Jun-14
4589759	Dabrafenib	Core	4-Aug-14	2-Sep-14
4589759	Trametinib_Dimethyl_Sulfoxide	Core	4-Aug-14	2-Sep-14
4589759	Trametinib_Dimethyl_Sulfoxide	Core	17-Sep-14	16-Oct-14
4589759	Dabrafenib	Core	26-Sep-14	25-Oct-14
4589759	Dabrafenib	Core	15-Oct-14	15-Oct-14
4589759	Dabrafenib	Core	21-Nov-14	20-Dec-14
4589759	Trametinib_Dimethyl_Sulfoxide	Core	21-Nov-14	20-Dec-14
;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;Data I want -&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;patient_id &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drug &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;start_date &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end_date &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lot&lt;BR /&gt;245689 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dabrafenib &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;14-Apr-15 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 05MAY2015 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;BR /&gt;245689 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dabrafenib+ Trametinib Dimethyl Sulfoxide &amp;nbsp; &amp;nbsp;06MAY2015 &amp;nbsp; &amp;nbsp; 13JUL2015 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;BR /&gt;245689 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Nivolumab &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 14JUL2015 &amp;nbsp; &amp;nbsp; &amp;nbsp; 14JUL2015 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;BR /&gt;4589759 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Carboplatin+Paclitaxel &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01OCT2013 &amp;nbsp; &amp;nbsp; &amp;nbsp;21OCT2013 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;BR /&gt;4589759 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Carboplatin+Paclitaxel+Temozolomide &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 25OCT2013 &amp;nbsp; &amp;nbsp; &amp;nbsp;21NOV2013 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;BR /&gt;4589759 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Paclitaxel &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 23JUN2014 &amp;nbsp; &amp;nbsp; &amp;nbsp; 27JUN2014 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;BR /&gt;4589759 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dabrafenib+Trametinib Dimethyl Sulfoxide &amp;nbsp; &amp;nbsp; 04AUG2014 &amp;nbsp; &amp;nbsp; &amp;nbsp;20DEC2014 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Data I am currently getting -&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;patient_id &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drug &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;start_date &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end_date &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lot&lt;BR /&gt;245689 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dabrafenib &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;14-Apr-15 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;05MAY2015 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;BR /&gt;245689 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Trametinib Dimethyl Sulfoxide+Dabrafenib &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 06MAY2015 &amp;nbsp; &amp;nbsp;13JUL2015 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;BR /&gt;245689 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Nivolumab+Dabrafenib+Trametinib Dimethyl Sulfoxide &amp;nbsp; &amp;nbsp;14JUL2015 &amp;nbsp; &amp;nbsp; &amp;nbsp;24JUL2015 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;BR /&gt;4589759 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Carboplatin+Paclitaxel &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01OCT2013 &amp;nbsp; &amp;nbsp; 21OCT2013 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;BR /&gt;4589759 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Temozolomide+Paclitaxel+Carboplatin &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 25OCT2013 &amp;nbsp; &amp;nbsp; 27DEC2013 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;BR /&gt;4589759 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Paclitaxel &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;23JUN2014 &amp;nbsp; &amp;nbsp; &amp;nbsp;27JUN2014 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;BR /&gt;4589759 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Dabrafenib+Trametinib Dimethyl Sulfoxide &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;04AUG2014 &amp;nbsp; &amp;nbsp; &amp;nbsp;20DEC2014 &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks in advance.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jul 2017 21:38:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/378334#M90880</guid>
      <dc:creator>ani_89</dc:creator>
      <dc:date>2017-07-21T21:38:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the desired output data to determine treatment pattern?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/378354#M90885</link>
      <description>&lt;P&gt;Based on one of your responses I had removed the core requirement to increase dates. It's included, again, below.&lt;/P&gt;
&lt;P&gt;The analysis appears to correctly deal with patient 4589759.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't recall ever seeing data for patient 245689, thus can't respond:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;/* last revised 21JUL2017 1:02 pm EDT, but 14JUL2017 was better*/
data have;
length patient_id $15. drug_name $50. ;
infile cards delimiter='09'x;
input patient_id (drug_name drug_type) ($) (start end) (: date11.);
  format start end  date9.;
/* 14526897	Interferon_Alfa_2b	Non_core	3-Sep-14	30-Sep-14 */
  cards;
14526897	Interferon_Alfa_2b	Non_core	11-Aug-14	11-Aug-14
14526897	Interferon_Alfa_2b	Non_core	12-Aug-14	12-Aug-14
14526897	Interferon_Alfa_2b	Non_core	13-Aug-14	13-Aug-14
14526897	Interferon_Alfa_2b	Non_core	14-Aug-14	14-Aug-14
14526897	Interferon_Alfa_2b	Non_core	15-Aug-14	15-Aug-14
14526897	Interferon_Alfa_2b	Non_core	18-Aug-14	18-Aug-14
14526897	Interferon_Alfa_2b	Non_core	19-Aug-14	19-Aug-14
14526897	Interferon_Alfa_2b	Non_core	20-Aug-14	20-Aug-14
14526897	Interferon_Alfa_2b	Non_core	21-Aug-14	21-Aug-14
14526897	Interferon_Alfa_2b	Non_core	22-Aug-14	22-Aug-14
14526897	Interferon_Alfa_2b	Non_core	25-Aug-14	25-Aug-14
14526897	Interferon_Alfa_2b	Non_core	26-Aug-14	26-Aug-14
14526897	Interferon_Alfa_2b	Non_core	27-Aug-14	27-Aug-14
14526897	Interferon_Alfa_2b	Non_core	28-Aug-14	28-Aug-14
14526897	Interferon_Alfa_2b	Non_core	2-Sep-14	2-Sep-14
14526897	Interferon_Alfa_2b	Non_core	3-Sep-14	3-Sep-14
14526897	Interferon_Alfa_2b	Non_core	4-Sep-14	4-Sep-14
14526897	Interferon_Alfa_2b	Non_core	5-Sep-14	5-Sep-14
14526897	Interferon_Alfa_2b	Non_core	8-Sep-14	8-Sep-14
14526897	Interferon_Alfa_2b	Non_core	9-Sep-14	9-Sep-14
14526897	Interferon_Alfa_2b	Non_core	13-Nov-14	10-Dec-14
14526897	Interferon_Alfa_2b	Non_core	23-Dec-14	19-Jan-15
14526897	Interferon_Alfa_2b	Non_core	9-Jan-15	5-Feb-15
14526897	Interferon_Alfa_2b	Non_core	27-Feb-15	26-Mar-15
14526897	Interferon_Alfa_2b	Non_core	17-Jun-15	14-Jul-15
897452634	Cisplatin	Non_core	19-Jan-16	19-Jan-16
897452634	Dacarbazine	Non_core	19-Jan-16	19-Jan-16
897452634	Ipilimumab	Core	19-Jan-16	19-Jan-16
897452634	Vinblastine	Non_core	19-Jan-16	19-Jan-16
897452634	Cisplatin	Non_core	20-Jan-16	20-Jan-16
897452634	Vinblastine	Non_core	20-Jan-16	20-Jan-16
897452634	Cisplatin	Non_core	21-Jan-16	21-Jan-16
897452634	Vinblastine	Non_core	21-Jan-16	21-Jan-16
897452634	Vinblastine	Non_core	22-Jan-16	22-Jan-16
897452634	Cisplatin	Non_core	9-Feb-16	9-Feb-16
897452634	Dacarbazine	Non_core	9-Feb-16	9-Feb-16
897452634	Ipilimumab	Core	9-Feb-16	9-Feb-16
897452634	Vinblastine	Non_core	9-Feb-16	9-Feb-16
897452634	Cisplatin	Non_core	10-Feb-16	10-Feb-16
897452634	Vinblastine	Non_core	10-Feb-16	10-Feb-16
897452634	Cisplatin	Non_core	11-Feb-16	11-Feb-16
897452634	Vinblastine	Non_core	11-Feb-16	11-Feb-16
897452634	Vinblastine	Non_core	12-Feb-16	12-Feb-16
897452634	Cisplatin	Non_core	1-Mar-16	1-Mar-16
897452634	Dacarbazine	Non_core	1-Mar-16	1-Mar-16
897452634	Ipilimumab	Core	1-Mar-16	1-Mar-16
897452634	Vinblastine	Non_core	1-Mar-16	1-Mar-16
897452634	Cisplatin	Non_core	2-Mar-16	2-Mar-16
897452634	Vinblastine	Non_core	2-Mar-16	2-Mar-16
897452634	Cisplatin	Non_core	3-Mar-16	3-Mar-16
897452634	Vinblastine	Non_core	3-Mar-16	3-Mar-16
897452634	Cisplatin	Non_core	22-Mar-16	22-Mar-16
897452634	Dacarbazine	Non_core	22-Mar-16	22-Mar-16
897452634	Ipilimumab	Core	22-Mar-16	22-Mar-16
897452634	Vinblastine	Non_core	22-Mar-16	22-Mar-16
897452634	Cisplatin	Non_core	23-Mar-16	23-Mar-16
897452634	Vinblastine	Non_core	23-Mar-16	23-Mar-16
897452634	Cisplatin	Non_core	24-Mar-16	24-Mar-16
897452634	Vinblastine	Non_core	24-Mar-16	24-Mar-16
587956	Ipilimumab	Core	31-May-13	22-Aug-13
587956	Ipilimumab	Core	3-Jun-13	3-Jun-13
587956	Dacarbazine	Non_core	4-Jun-13	4-Jun-13
587956	Ipilimumab	Core	4-Jun-13	4-Jun-13
587956	Ipilimumab	Core	14-Jun-13	14-Jun-13
587956	Dacarbazine	Non_core	1-Jul-13	1-Jul-13
587956	Ipilimumab	Core	1-Jul-13	1-Jul-13
587956	Ipilimumab	Core	3-Jul-13	3-Jul-13
587956	Dacarbazine	Non_core	30-Jul-13	30-Jul-13
587956	Ipilimumab	Core	30-Jul-13	30-Jul-13
587956	Dacarbazine	Non_core	27-Aug-13	27-Aug-13
587956	Ipilimumab	Core	27-Aug-13	27-Aug-13
587956	Ipilimumab	Core	14-Oct-13	14-Oct-13
587956	Dacarbazine	Non_core	15-Oct-13	15-Oct-13
9874526	Vemurafenib	Core	9-May-13	7-Jun-13
9874526	Vemurafenib	Core	11-Jun-13	10-Jul-13
9874526	Vemurafenib	Core	13-Jun-13	13-Jun-13
9874526	Vemurafenib	Core	11-Jul-13	11-Jul-13
9874526	Vemurafenib	Core	13-Jul-13	11-Aug-13
9874526	Vemurafenib	Core	13-Aug-13	13-Aug-13
9874526	Dabrafenib	Core	19-Aug-13	17-Sep-13
9874526	Trametinib_Dimethyl_Sulfoxide	Core	19-Aug-13	17-Sep-13
9874526	Trametinib_Dimethyl_Sulfoxide	Core	10-Sep-13	10-Sep-13
9874526	Trametinib_Dimethyl_Sulfoxide	Core	18-Sep-13	17-Oct-13
9874526	Dabrafenib	Core	23-Sep-13	22-Oct-13
9874526	Dabrafenib	Core	8-Oct-13	8-Oct-13
9874526	Dabrafenib	Core	21-Oct-13	19-Nov-13
9874526	Trametinib_Dimethyl_Sulfoxide	Core	21-Oct-13	19-Nov-13
9874526	Trametinib_Dimethyl_Sulfoxide	Core	6-Nov-13	6-Nov-13
9874526	Dabrafenib	Core	18-Nov-13	17-Dec-13
9874526	Trametinib_Dimethyl_Sulfoxide	Core	18-Nov-13	17-Dec-13
9874526	Trametinib_Dimethyl_Sulfoxide	Core	5-Dec-13	5-Dec-13
9874526	Dabrafenib	Core	23-Dec-13	21-Jan-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	23-Dec-13	21-Jan-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	2-Jan-14	2-Jan-14
9874526	Dabrafenib	Core	20-Jan-14	18-Feb-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	20-Jan-14	18-Feb-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	11-Feb-14	12-Mar-14
9874526	Dabrafenib	Core	18-Feb-14	19-Mar-14
9874526	Dabrafenib	Core	25-Feb-14	25-Feb-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	1-Apr-14	30-Apr-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	6-May-14	6-May-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	7-May-14	5-Jun-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	3-Jun-14	3-Jun-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	6-Jun-14	5-Jul-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	8-Jul-14	6-Aug-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	17-Jul-14	17-Jul-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	7-Aug-14	5-Sep-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	20-Aug-14	20-Aug-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	3-Sep-14	2-Oct-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	18-Sep-14	18-Sep-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	2-Oct-14	31-Oct-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	16-Oct-14	16-Oct-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	4-Nov-14	3-Dec-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	12-Nov-14	12-Nov-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	15-Dec-14	13-Jan-15
9874526	Trametinib_Dimethyl_Sulfoxide	Core	16-Dec-14	16-Dec-14
9874526	Trametinib_Dimethyl_Sulfoxide	Core	13-Jan-15	11-Feb-15
9874526	Trametinib_Dimethyl_Sulfoxide	Core	10-Feb-15	10-Feb-15
9874526	Trametinib_Dimethyl_Sulfoxide	Core	19-Feb-15	20-Mar-15
9874526	Trametinib_Dimethyl_Sulfoxide	Core	19-Mar-15	19-Mar-15
9874526	Trametinib_Dimethyl_Sulfoxide	Core	14-Apr-15	13-May-15
9874526	Trametinib_Dimethyl_Sulfoxide	Core	23-Apr-15	23-Apr-15
9874526	Trametinib_Dimethyl_Sulfoxide	Core	14-May-15	12-Jun-15
9874526	Trametinib_Dimethyl_Sulfoxide	Core	11-Jun-15	10-Jul-15
9874526	Trametinib_Dimethyl_Sulfoxide	Core	30-Jun-15	30-Jun-15
9874526	Trametinib_Dimethyl_Sulfoxide	Core	28-Jul-15	28-Jul-15
9874526	Trametinib_Dimethyl_Sulfoxide	Core	29-Jul-15	27-Aug-15
9874526	Trametinib_Dimethyl_Sulfoxide	Core	26-Aug-15	26-Aug-15
9874526	Trametinib_Dimethyl_Sulfoxide	Core	2-Sep-15	1-Oct-15
9874526	Vemurafenib	Core	2-Sep-15	1-Oct-15
9874526	Vemurafenib	Core	24-Sep-15	24-Sep-15
9874526	Trametinib_Dimethyl_Sulfoxide	Core	30-Sep-15	29-Oct-15
9874526	Vemurafenib	Core	23-Oct-15	21-Nov-15
9874526	Cobimetinib	Core	4-Dec-15	9-Jan-16
9874526	Cobimetinib	Core	23-Dec-15	23-Dec-15
9874526	Cobimetinib	Core	4-Jan-16	9-Feb-16
9874526	Ipilimumab	Core	3-Feb-16	3-Feb-16
9874526	Nivolumab	Core	3-Feb-16	3-Feb-16
874512399	Dabrafenib	Core	25-Apr-14	24-May-14
874512399	Trametinib_Dimethyl_Sulfoxide	Core	29-Apr-14	28-May-14
874512399	Trametinib_Dimethyl_Sulfoxide	Core	30-May-14	28-Jun-14
874512399	Dabrafenib	Core	2-Jun-14	1-Jul-14
874512399	Trametinib_Dimethyl_Sulfoxide	Core	4-Aug-14	2-Sep-14
874512399	Dabrafenib	Core	5-Aug-14	3-Sep-14
874512399	Dabrafenib	Core	16-Sep-14	15-Oct-14
874512399	Trametinib_Dimethyl_Sulfoxide	Core	16-Sep-14	15-Oct-14
874512399	Trametinib_Dimethyl_Sulfoxide	Core	11-Nov-14	11-Nov-14
874512399	Trametinib_Dimethyl_Sulfoxide	Core	1-Dec-14	1-Dec-14
874512399	Trametinib_Dimethyl_Sulfoxide	Core	21-Dec-14	21-Dec-14
874512399	Trametinib_Dimethyl_Sulfoxide	Core	22-Dec-14	22-Dec-14
874512399	Trametinib_Dimethyl_Sulfoxide	Core	21-Jan-15	21-Jan-15
874512399	Trametinib_Dimethyl_Sulfoxide	Core	16-Apr-15	16-Apr-15
874512399	Bevacizumab	Non_core	1-May-15	1-May-15
874512399	Bevacizumab	Non_core	18-May-15	18-May-15
874512399	Bevacizumab	Non_core	2-Jun-15	2-Jun-15
874512399	Bevacizumab	Non_core	16-Jun-15	16-Jun-15
874512399	Bevacizumab	Non_core	8-Jul-15	8-Jul-15
874512399	Bevacizumab	Non_core	22-Jul-15	22-Jul-15
874512399	Bevacizumab	Non_core	5-Aug-15	5-Aug-15
874512399	Bevacizumab	Non_core	25-Aug-15	25-Aug-15
874512399	Bevacizumab	Non_core	17-Sep-15	17-Sep-15
874512399	Bevacizumab	Non_core	1-Oct-15	1-Oct-15
874512399	Bevacizumab	Non_core	14-Oct-15	14-Oct-15
874512399	Bevacizumab	Non_core	27-Oct-15	27-Oct-15
874512399	Bevacizumab	Non_core	13-Nov-15	13-Nov-15
874512399	Bevacizumab	Non_core	4-Dec-15	4-Dec-15
874512399	Bevacizumab	Non_core	24-Dec-15	24-Dec-15
874512399	Bevacizumab	Non_core	15-Jan-16	15-Jan-16
874512399	Bevacizumab	Non_core	5-Feb-16	5-Feb-16
874512399	Bevacizumab	Non_core	26-Feb-16	26-Feb-16
874512399	Bevacizumab	Non_core	18-Mar-16	18-Mar-16
874512399	Bevacizumab	Non_core	8-Apr-16	8-Apr-16
874512399	Pembrolizumab	Core	8-Apr-16	8-Apr-16
74521369845	Cisplatin	Non_core	29-Jul-14	29-Jul-14
74521369845	Dacarbazine	Non_core	29-Jul-14	29-Jul-14
74521369845	Vinblastine	Non_core	29-Jul-14	29-Jul-14
74521369845	Cisplatin	Non_core	30-Jul-14	30-Jul-14
74521369845	Vinblastine	Non_core	30-Jul-14	30-Jul-14
74521369845	Cisplatin	Non_core	31-Jul-14	31-Jul-14
74521369845	Vinblastine	Non_core	31-Jul-14	31-Jul-14
74521369845	Cisplatin	Non_core	26-Aug-14	26-Aug-14
74521369845	Dacarbazine	Non_core	26-Aug-14	26-Aug-14
74521369845	Ipilimumab	Core	26-Aug-14	26-Aug-14
74521369845	Vinblastine	Non_core	26-Aug-14	26-Aug-14
74521369845	Cisplatin	Non_core	27-Aug-14	27-Aug-14
74521369845	Vinblastine	Non_core	27-Aug-14	27-Aug-14
74521369845	Cisplatin	Non_core	28-Aug-14	28-Aug-14
74521369845	Vinblastine	Non_core	28-Aug-14	28-Aug-14
74521369845	Cisplatin	Non_core	16-Sep-14	16-Sep-14
74521369845	Dacarbazine	Non_core	16-Sep-14	16-Sep-14
74521369845	Ipilimumab	Core	16-Sep-14	16-Sep-14
74521369845	Vinblastine	Non_core	16-Sep-14	16-Sep-14
74521369845	Cisplatin	Non_core	17-Sep-14	17-Sep-14
74521369845	Vinblastine	Non_core	17-Sep-14	17-Sep-14
74521369845	Cisplatin	Non_core	18-Sep-14	18-Sep-14
74521369845	Vinblastine	Non_core	18-Sep-14	18-Sep-14
74521369845	Vinblastine	Non_core	19-Sep-14	19-Sep-14
74521369845	Cisplatin	Non_core	7-Oct-14	7-Oct-14
74521369845	Dacarbazine	Non_core	7-Oct-14	7-Oct-14
74521369845	Ipilimumab	Core	7-Oct-14	7-Oct-14
74521369845	Vinblastine	Non_core	7-Oct-14	7-Oct-14
74521369845	Cisplatin	Non_core	8-Oct-14	8-Oct-14
74521369845	Vinblastine	Non_core	8-Oct-14	8-Oct-14
74521369845	Cisplatin	Non_core	9-Oct-14	9-Oct-14
74521369845	Vinblastine	Non_core	9-Oct-14	9-Oct-14
74521369845	Vinblastine	Non_core	10-Oct-14	10-Oct-14
74521369845	Cisplatin	Non_core	28-Oct-14	28-Oct-14
74521369845	Dacarbazine	Non_core	28-Oct-14	28-Oct-14
74521369845	Vinblastine	Non_core	28-Oct-14	28-Oct-14
74521369845	Cisplatin	Non_core	29-Oct-14	29-Oct-14
74521369845	Vinblastine	Non_core	29-Oct-14	29-Oct-14
74521369845	Cisplatin	Non_core	30-Oct-14	30-Oct-14
74521369845	Vinblastine	Non_core	30-Oct-14	30-Oct-14
74521369845	Cisplatin	Non_core	2-Dec-14	2-Dec-14
74521369845	Dacarbazine	Non_core	2-Dec-14	2-Dec-14
74521369845	Vinblastine	Non_core	2-Dec-14	2-Dec-14
74521369845	Cisplatin	Non_core	3-Dec-14	3-Dec-14
74521369845	Vinblastine	Non_core	3-Dec-14	3-Dec-14
74521369845	Cisplatin	Non_core	4-Dec-14	4-Dec-14
74521369845	Vinblastine	Non_core	4-Dec-14	4-Dec-14
4526789	Interleukin-2	Core	26-Oct-15	31-Oct-15
4526789	Interleukin-2	Core	27-Oct-15	27-Oct-15
4526789	Interleukin-2	Core	28-Oct-15	28-Oct-15
4526789	Interleukin-2	Core	29-Oct-15	29-Oct-15
4526789	Interleukin-2	Core	30-Oct-15	30-Oct-15
4526789	Interleukin-2	Core	31-Oct-15	31-Oct-15
4526789	Interferon_Alfa_2b	Non_core	2-Nov-15	29-Nov-15
4526789	Interferon_Alfa_2b	Non_core	16-Nov-15	20-Nov-15
4526789	Interferon_Alfa_2b	Non_core	17-Nov-15	17-Nov-15
4526789	Interferon_Alfa_2b	Non_core	18-Nov-15	18-Nov-15
4526789	Interferon_Alfa_2b	Non_core	19-Nov-15	19-Nov-15
4526789	Interferon_Alfa_2b	Non_core	20-Nov-15	20-Nov-15
4526789	Interferon_Alfa_2b	Non_core	7-Dec-15	3-Jan-16
4526789	Interleukin-2	Core	7-Dec-15	11-Dec-15
4526789	Interleukin-2	Core	8-Dec-15	8-Dec-15
4526789	Interleukin-2	Core	9-Dec-15	9-Dec-15
4526789	Interleukin-2	Core	10-Dec-15	10-Dec-15
4526789	Interleukin-2	Core	11-Dec-15	11-Dec-15
4526789	Pembrolizumab	Core	30-Mar-16	30-Mar-16
4526789	Pembrolizumab	Core	20-Apr-16	20-Apr-16
4526789	Pembrolizumab	Core	11-May-16	11-May-16
4526789	Pembrolizumab	Core	18-May-16	18-May-16
4526789	Pembrolizumab	Core	8-Jun-16	8-Jun-16
4526789	Pembrolizumab	Core	29-Jun-16	29-Jun-16
78954526	Dabrafenib	Core	25-Apr-14	24-May-14
78954526	Trametinib_Dimethyl_Sulfoxide	Core	25-Apr-14	24-May-14
78954526	Dabrafenib	Core	30-Apr-14	29-May-14
78954526	Trametinib_Dimethyl_Sulfoxide	Core	30-Apr-14	29-May-14
78954526	Dabrafenib	Core	29-May-14	27-Jun-14
78954526	Trametinib_Dimethyl_Sulfoxide	Core	29-May-14	27-Jun-14
78954526	Dabrafenib	Core	25-Jun-14	24-Jul-14
78954526	Trametinib_Dimethyl_Sulfoxide	Core	25-Jun-14	24-Jul-14
78954526	Dabrafenib	Core	18-Aug-14	16-Sep-14
78954526	Trametinib_Dimethyl_Sulfoxide	Core	18-Aug-14	16-Sep-14
78954526	Dabrafenib	Core	15-Sep-14	14-Oct-14
78954526	Trametinib_Dimethyl_Sulfoxide	Core	15-Sep-14	14-Oct-14
78954526	Ipilimumab	Core	9-Oct-14	9-Oct-14
8745120369	Dabrafenib	Core	18-Aug-14	16-Sep-14
8745120369	Dabrafenib	Core	20-Aug-14	18-Sep-14
8745120369	Trametinib_Dimethyl_Sulfoxide	Core	26-Aug-14	24-Sep-14
8745120369	Trametinib_Dimethyl_Sulfoxide	Core	23-Sep-14	21-Dec-14
8745120369	Dabrafenib	Core	17-Oct-14	14-Jan-15
8745120369	Ipilimumab	Core	22-Dec-14	22-Dec-14
4589759	Carboplatin	Non_core	1-Oct-13	1-Oct-13
4589759	Paclitaxel	Non_core	1-Oct-13	1-Oct-13
4589759	Carboplatin	Non_core	7-Oct-13	7-Oct-13
4589759	Paclitaxel	Non_core	7-Oct-13	7-Oct-13
4589759	Carboplatin	Non_core	14-Oct-13	14-Oct-13
4589759	Paclitaxel	Non_core	14-Oct-13	14-Oct-13
4589759	Carboplatin	Non_core	21-Oct-13	21-Oct-13
4589759	Paclitaxel	Non_core	21-Oct-13	21-Oct-13
4589759	Temozolomide	Core	25-Oct-13	21-Nov-13
4589759	Paclitaxel	Non_core	30-Oct-13	30-Oct-13
4589759	Paclitaxel	Non_core	5-Nov-13	5-Nov-13
4589759	Carboplatin	Non_core	13-Nov-13	13-Nov-13
4589759	Paclitaxel	Non_core	13-Nov-13	13-Nov-13
4589759	Carboplatin	Non_core	19-Nov-13	19-Nov-13
4589759	Paclitaxel	Non_core	19-Nov-13	19-Nov-13
4589759	Carboplatin	Non_core	27-Nov-13	27-Nov-13
4589759	Paclitaxel	Non_core	27-Nov-13	27-Nov-13
4589759	Carboplatin	Non_core	4-Dec-13	4-Dec-13
4589759	Paclitaxel	Non_core	4-Dec-13	4-Dec-13
4589759	Carboplatin	Non_core	11-Dec-13	11-Dec-13
4589759	Paclitaxel	Non_core	11-Dec-13	11-Dec-13
4589759	Paclitaxel	Non_core	27-Dec-13	27-Dec-13
4589759	Paclitaxel	Non_core	23-Jun-14	27-Jun-14
4589759	Dabrafenib	Core	4-Aug-14	2-Sep-14
4589759	Trametinib_Dimethyl_Sulfoxide	Core	4-Aug-14	2-Sep-14
4589759	Trametinib_Dimethyl_Sulfoxide	Core	17-Sep-14	16-Oct-14
4589759	Dabrafenib	Core	26-Sep-14	25-Oct-14
4589759	Dabrafenib	Core	15-Oct-14	15-Oct-14
4589759	Dabrafenib	Core	21-Nov-14	20-Dec-14
4589759	Trametinib_Dimethyl_Sulfoxide	Core	21-Nov-14	20-Dec-14
;

data want
 (keep=patient_id drug start_date end_date lot)
 ;
  set have;
  by patient_id notsorted;
  format start_date end_date date9.;

  /* look ahead at next record */
  set have ( firstobs = 2 keep = start drug_type drug_name 
              rename = (start = next_start drug_type=next_type drug_name=next_drug) )
      have (      obs = 1 drop = _all_ );
  next_start = ifn(last.patient_id, (.), next_start );
  next_type = ifc(last.patient_id, (.), next_type );
  next_drug = ifc(last.patient_id, (.), next_drug );
 
  /* set length of drug to be wide enough to fix all drugs */
  length drug $1000.;
  length hold_drug $1000.;
  array adrugs(100) $ 30 adrug1-adrug100;
  array adates(100) adate1-adate100;

  array hold_drugs(100) $ 30  hold_drug1-hold_drug100;
  array hold_dates(100) hold_date1-hold_date100;

 format adate1-adate20 date9.;
  retain start_date end_date drug days adrug: adate: hold_drug: hold_date:;
    
  /* initialize variables for first record within a given lot */
  if first.patient_id or counter eq 0 then do;
    if first.patient_id then do;
      lot=0;
      call missing (of adrugs(*));
      call missing (of adates(*));
      call missing (of hold_drugs(*));
      call missing (of hold_dates(*));
      dcounter=0;
    end;
    start_date=start;
    end_date=end;
    counter=1;
    drug='';
    hold_drug='';
          
    if drug_type eq 'Core' then do;
      drug=drug_name;
      dcounter+1;
      adrugs(dcounter)=drug_name;
      adates(dcounter)=end;
      do i=1 to dim(adrugs);
        if (not missing(adrugs(i))) and adates(i) ge start_date then do;
          if adrugs(i) ne strip(drug_name) then do;
            drug=catx('+',drug,adrugs(i));
            end_date=max(end_date,adates(i));
          end;
        end;
        else do;
          call missing(adrugs(i));
          call missing(adates(i));
        end;
      end;
    end;
    else do;
      call missing (of hold_drugs(*));
      call missing (of hold_dates(*));
      hold_drug=drug_name;
      dcounter+1;
      hold_drugs(dcounter)=drug_name;
      hold_dates(dcounter)=end;
    end;
    if next_start gt start_date+21 or missing(next_start) then do;
      days=60;
      if missing(drug) then do;
        drug=hold_drug;
        do i=1 to dim(adrugs);
          if (not missing(adrugs(i))) and adates(i) ge start_date then do;
            if strip(drug_name) ne adrugs(i) then drug=catx('+',drug,adrugs(i));
            end_date=max(end_date,adates(i));
          end;
          else do;
            call missing(adrugs(i));
            call missing(adates(i));
          end;
          if (not missing(hold_drugs(i))) and hold_dates(i) ge start_date then do;
            if strip(drug_name) ne hold_drugs(i) then rug=catx('+',drug,hold_drugs(i));
            end_date=max(end_date,hold_dates(i));
          end;
          else do;
            call missing(hold_drugs(i));
            call missing(hold_dates(i));
          end;
        end;
        call missing(of hold_drugs(*));
        call missing(of hold_dates(*));
        call missing(hold_drug);
      end;
    end;
    else days=21;
  end;
  
  
  
  /* if not first record in lot and still within 21 day period check to see if drug in drug list */
  else if days eq 21 then do;
    if drug_type eq 'Core' then do;
      if not findw(drug,strip(drug_name)) then do;
        drug=catx('+',drug,drug_name);
        dcounter+1;
        adrugs(dcounter)=drug_name;
        adates(dcounter)=end;
      end;
      do i=1 to dim(adrugs);
        if drug_name eq adrugs(i) and adates(i) lt start_date then do;
          adates(i)=end;
        end;
      end;
      counter+1;
      end_date=max(end_date,end);
    end;
    
    else if missing(drug) then do;
      if not findw(hold_drug,strip(drug_name)) then do;
        hold_drug=catx('+',hold_drug,drug_name);
        dcounter+1;
        hold_drugs(dcounter)=drug_name;
        hold_dates(dcounter)=end;
      end;
      do i=1 to dim(adrugs);
        if drug_name eq hold_drugs(i) and hold_dates(i) lt /*start_date*/ end then do;
          hold_dates(i)=end;
        end;
      end;
      end_date=max(end_date,end);
      counter+1;
    end;
 
    /* add Non_core if lot already has at least one core */
    else do;
      if not findw(drug,strip(drug_name)) then do;
        drug=catx('+',drug,drug_name);
        dcounter+1;
        adrugs(dcounter)=drug_name;
        adates(dcounter)=end;
      end;
      counter+1;
    end;

    if next_start gt start_date+21 or missing(next_start) then do;
      days=60;
      if missing(drug) then do;
        drug=hold_drug;
        do i=1 to dim(adrugs);
          if (not missing(adrugs(i))) and adates(i) ge start_date then do;
/*             drug=catx('+',drug,adrugs(i)); */
            end_date=max(end_date,adates(i));
          end;
          else do;
            call missing(adrugs(i));
            call missing(adates(i));
          end;
          if (not missing(hold_drugs(i))) and hold_dates(i) ge start_date then do;
/*             drug=catx('+',drug,hold_drugs(i)); */
            end_date=max(end_date,hold_dates(i));
          end;
          else do;
            call missing(hold_drugs(i));
            call missing(hold_dates(i));
          end;
        end;
        call missing(of hold_drugs(*));
        call missing(of hold_dates(*));
        call missing(hold_drug);
      end;
    end;
  end;

  /* within 60 day check */
  else do;
    days=60;
/*     if start le end_date+60 and findw(drug,strip(drug_name)) /* and drug_type eq 'Core'* / then do; */
    if start le end_date+60 and findw(drug,strip(drug_name)) and drug_type eq 'Core' then do;
      counter+1;
      end_date=max(end,end_date);
      do i=1 to dim(adrugs);
        if adrugs(i) eq strip(drug_name) then do;
          adates(i)=max(adates(i),end);
        end;
      end;
    end;
  end;
*output;
  
  /* check to see if last.patient_id or next record indicates new lot */
  if last.patient_id or
     (counter gt 0 and
     days eq 60 and
     (next_start gt end_date+60 or
      ((not findw(drug,strip(next_drug))) and
       next_type eq 'Core')))
  then do;
    if not missing(next_start) and next_start le end_date then end_date=next_start-1;
    lot+1;
    output;
    counter=0;
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jul 2017 16:43:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-the-desired-output-data-to-determine-treatment/m-p/378354#M90885</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-22T16:43:09Z</dc:date>
    </item>
  </channel>
</rss>

