<?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: subsetting based on two dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/subsetting-based-on-two-dates/m-p/309857#M66768</link>
    <description>&lt;P&gt;both produces an error.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 07 Nov 2016 20:43:04 GMT</pubDate>
    <dc:creator>lillymaginta</dc:creator>
    <dc:date>2016-11-07T20:43:04Z</dc:date>
    <item>
      <title>subsetting based on two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subsetting-based-on-two-dates/m-p/309548#M66628</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;id start date  drug end_Date 
1 01/01/2005 a     04/01/2005
1  02/01/2005 b    03/04/2005
2  02/03/2005 a    03/04/2005
2   01/02/2004  b    02/02/2004&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have the following database with multiple ids and only two drugs a and b. I want to create a database for drug a but to change the end date based on the start of drug. Here are my assumptions:&lt;/P&gt;&lt;P&gt;For patients 1, the start date is the same but the end date for drug a would be the start of drug b.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For patient 2, do not include because drug b started before a&lt;/P&gt;&lt;P&gt;each drug has one start and one end date&amp;nbsp;&lt;/P&gt;&lt;P&gt;My output would look like this&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;id start date  drug end_Date 
1 01/01/2005 a     02/01/2005&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Nov 2016 00:11:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subsetting-based-on-two-dates/m-p/309548#M66628</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2016-11-06T00:11:13Z</dc:date>
    </item>
    <item>
      <title>Re: subsetting based on two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subsetting-based-on-two-dates/m-p/309585#M66657</link>
      <description>&lt;P&gt;Something like this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   format id start_date drug end_Date;
   informat start_date end_date ddmmyy10.;
   input
   id $ start_date drug $ end_Date;

   format start_date end_date ddmmyy10.;

   datalines;
   1 01/01/2005 a 04/01/2005
   1 02/01/2005 b 03/04/2005
   2 02/03/2005 a 03/04/2005
   2 01/02/2004 b 02/02/2004
;

proc sort data = have;
   by descending id descending drug;
run;

data want;
   set have;

   if start_date &amp;lt; lag(start_date) then do;
      end_date = lag(start_date);
      if drug='a' then output;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 06 Nov 2016 10:33:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subsetting-based-on-two-dates/m-p/309585#M66657</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2016-11-06T10:33:11Z</dc:date>
    </item>
    <item>
      <title>Re: subsetting based on two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subsetting-based-on-two-dates/m-p/309588#M66659</link>
      <description>&lt;P&gt;Assuming there are only two obs for each id.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   format id start_date drug end_Date;
   informat start_date end_date ddmmyy10.;
   input
   id $ start_date drug $ end_Date;

   format start_date end_date ddmmyy10.;

   datalines;
   1 01/01/2005 a 04/01/2005
   1 02/01/2005 b 03/04/2005
   2 02/03/2005 a 03/04/2005
   2 01/02/2004 b 02/02/2004
;
run;
data want;
 merge have have(keep=id start_date rename=(id=_id start_date=_date) firstobs=2);
 if id=_id and start_date lt _date then do;
  end_date=_date;output;
 end;
 drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 06 Nov 2016 11:07:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subsetting-based-on-two-dates/m-p/309588#M66659</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-11-06T11:07:46Z</dc:date>
    </item>
    <item>
      <title>Re: subsetting based on two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subsetting-based-on-two-dates/m-p/309657#M66711</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/72105"&gt;@lillymaginta﻿&lt;/a&gt;&amp;nbsp;Did this solve your problem? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Nov 2016 07:38:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subsetting-based-on-two-dates/m-p/309657#M66711</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2016-11-07T07:38:06Z</dc:date>
    </item>
    <item>
      <title>Re: subsetting based on two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subsetting-based-on-two-dates/m-p/309857#M66768</link>
      <description>&lt;P&gt;both produces an error.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Nov 2016 20:43:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subsetting-based-on-two-dates/m-p/309857#M66768</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2016-11-07T20:43:04Z</dc:date>
    </item>
    <item>
      <title>Re: subsetting based on two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subsetting-based-on-two-dates/m-p/309962#M66801</link>
      <description>&lt;P&gt;What error are you getting?&lt;/P&gt;</description>
      <pubDate>Tue, 08 Nov 2016 07:07:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subsetting-based-on-two-dates/m-p/309962#M66801</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2016-11-08T07:07:29Z</dc:date>
    </item>
    <item>
      <title>Re: subsetting based on two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subsetting-based-on-two-dates/m-p/309964#M66802</link>
      <description>&lt;P&gt;This is my log running my solution&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/5695i93B8C2505D5AB46E/image-size/medium?v=v2&amp;amp;px=-1" border="0" alt="LOGLOG.PNG" title="LOGLOG.PNG" /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Nov 2016 07:09:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subsetting-based-on-two-dates/m-p/309964#M66802</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2016-11-08T07:09:27Z</dc:date>
    </item>
    <item>
      <title>Re: subsetting based on two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subsetting-based-on-two-dates/m-p/310014#M66815</link>
      <description>&lt;P&gt;in the original dataset that is exactly similar to the one above but with multiple ids, the code create missing data for some of the dates.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Nov 2016 10:49:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subsetting-based-on-two-dates/m-p/310014#M66815</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2016-11-08T10:49:29Z</dc:date>
    </item>
    <item>
      <title>Re: subsetting based on two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subsetting-based-on-two-dates/m-p/310068#M66820</link>
      <description>&lt;P&gt;Do you have any IDs for which there are more than two records?&lt;/P&gt;</description>
      <pubDate>Tue, 08 Nov 2016 14:03:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subsetting-based-on-two-dates/m-p/310068#M66820</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2016-11-08T14:03:59Z</dc:date>
    </item>
    <item>
      <title>Re: subsetting based on two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subsetting-based-on-two-dates/m-p/310681#M67032</link>
      <description>&lt;P&gt;no each id would have one period for drug a and another period for drug b. So only two per each.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Nov 2016 14:45:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subsetting-based-on-two-dates/m-p/310681#M67032</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2016-11-10T14:45:01Z</dc:date>
    </item>
    <item>
      <title>Re: subsetting based on two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subsetting-based-on-two-dates/m-p/310682#M67033</link>
      <description>&lt;P&gt;What error are you getting?&lt;/P&gt;</description>
      <pubDate>Thu, 10 Nov 2016 14:46:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subsetting-based-on-two-dates/m-p/310682#M67033</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2016-11-10T14:46:29Z</dc:date>
    </item>
  </channel>
</rss>

