<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Overlapping dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Overlapping-dates/m-p/622332#M183062</link>
    <description>&lt;P&gt;Why not&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2;
 	set test1;
 if startdate le reg_date le enddate then withinyr =1;
 if extdate le reg_date lt startdate then withingrace=1;
 if withinyr ne 1 and withingrace ne 1 then out=1;
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 04 Feb 2020 23:51:02 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2020-02-04T23:51:02Z</dc:date>
    <item>
      <title>Overlapping dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overlapping-dates/m-p/622317#M183056</link>
      <description>&lt;P&gt;Hello, the code for the sample data set I am working with is listed below.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data test1;&lt;BR /&gt; infile datalines delimiter = ',';&lt;BR /&gt; input id $ reg_date:mmddyy10. startdate:mmddyy10. enddate:mmddyy10. extdate:mmddyy10.  ;&lt;BR /&gt; format  reg_date startdate enddate extdate mmddyy10.;&lt;BR /&gt; datalines;&lt;BR /&gt; 100,11/30/2017,11/30/2017,11/30/2018,08/31/2017&lt;BR /&gt; 200,11/30/2017,11/30/2017,11/30/2018,08/31/2017&lt;BR /&gt; 300,11/30/2017,11/30/2017,11/30/2018,08/31/2017&lt;BR /&gt; ;&lt;BR /&gt; run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Flag variables are created in the data set with the code below.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; data test2;&lt;BR /&gt; 	set test1;&lt;BR /&gt; if startdate le reg_date le enddate then withinyr =1;&lt;BR /&gt; if extdate le reg_date le startdate then withingrace=1;&lt;BR /&gt; if withinyr ne 1 and withingrace ne 1 then out=1;&lt;BR /&gt; &lt;BR /&gt; run;&lt;/PRE&gt;
&lt;P&gt;If/then else was not used to create the flag variables because in certain instances&amp;nbsp; the dates overlap and cause a flag for withinyr and withingrace for the same id as pictured below. I would like to know if there is a way, I can flag just withinyr&amp;nbsp;&lt;/P&gt;
&lt;P&gt;when this issue happens?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE class="table" aria-label="Data Set WORK.TEST2"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;Obs&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;id&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;reg_date&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;startdate&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;enddate&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;extdate&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;withinyr&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;withingrace&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;out&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="data"&gt;100&lt;/TD&gt;
&lt;TD class="r data"&gt;11/30/2017&lt;/TD&gt;
&lt;TD class="r data"&gt;11/30/2017&lt;/TD&gt;
&lt;TD class="r data"&gt;11/30/2018&lt;/TD&gt;
&lt;TD class="r data"&gt;08/31/2017&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="data"&gt;200&lt;/TD&gt;
&lt;TD class="r data"&gt;11/30/2017&lt;/TD&gt;
&lt;TD class="r data"&gt;11/30/2017&lt;/TD&gt;
&lt;TD class="r data"&gt;11/30/2018&lt;/TD&gt;
&lt;TD class="r data"&gt;08/31/2017&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="data"&gt;300&lt;/TD&gt;
&lt;TD class="r data"&gt;11/30/2017&lt;/TD&gt;
&lt;TD class="r data"&gt;11/30/2017&lt;/TD&gt;
&lt;TD class="r data"&gt;11/30/2018&lt;/TD&gt;
&lt;TD class="r data"&gt;08/31/2017&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Tue, 04 Feb 2020 22:34:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overlapping-dates/m-p/622317#M183056</guid>
      <dc:creator>luvscandy27</dc:creator>
      <dc:date>2020-02-04T22:34:49Z</dc:date>
    </item>
    <item>
      <title>Re: Overlapping dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overlapping-dates/m-p/622325#M183059</link>
      <description>&lt;P&gt;Your IF statements should look like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; if startdate le reg_date and startdate le enddate then withinyr =1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;then these are computed correctly and OUT will be computed correctly as well. &lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 23:17:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overlapping-dates/m-p/622325#M183059</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-02-04T23:17:32Z</dc:date>
    </item>
    <item>
      <title>Re: Overlapping dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overlapping-dates/m-p/622327#M183060</link>
      <description>&lt;P&gt;Are you trying to test if two ranges overlap?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's make a picture.&amp;nbsp; Say you have one range from A to B and the second range from C to D.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;----+---0----+---0----+---0----+---0
  ^        ^
  +-A----B-+
----+---0----+---0----+---0----+---0
      ^        ^
      +-C----D-+&lt;/PRE&gt;
&lt;P&gt;then they overlap when&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;D&amp;gt;=A and C&amp;lt;=B&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The second is contained in the first when&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;A&amp;lt;=C&amp;lt;=B and A&amp;lt;=D&amp;lt;=B&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Feb 2020 23:28:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overlapping-dates/m-p/622327#M183060</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-04T23:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: Overlapping dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overlapping-dates/m-p/622329#M183061</link>
      <description>&lt;P&gt;Thank you. Just make sure I understand&amp;nbsp; I could write my code like below and it would be correct? And their would be no chance of flagging withinyr and withingrace at the sametime.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if startdate le reg_date and startdate le enddate then withinyr =1;&lt;BR /&gt; 	else if  startdate le reg_date and startdate le extdate then withingrace =1;&lt;BR /&gt; 		else  out = 1;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 23:45:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overlapping-dates/m-p/622329#M183061</guid>
      <dc:creator>luvscandy27</dc:creator>
      <dc:date>2020-02-04T23:45:56Z</dc:date>
    </item>
    <item>
      <title>Re: Overlapping dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overlapping-dates/m-p/622332#M183062</link>
      <description>&lt;P&gt;Why not&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2;
 	set test1;
 if startdate le reg_date le enddate then withinyr =1;
 if extdate le reg_date lt startdate then withingrace=1;
 if withinyr ne 1 and withingrace ne 1 then out=1;
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Feb 2020 23:51:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overlapping-dates/m-p/622332#M183062</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-02-04T23:51:02Z</dc:date>
    </item>
    <item>
      <title>Re: Overlapping dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overlapping-dates/m-p/622334#M183063</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/255656"&gt;@luvscandy27&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you. Just make sure I understand&amp;nbsp; I could write my code like below and it would be correct? And their would be no chance of flagging withinyr and withingrace at the sametime.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if startdate le reg_date and startdate le enddate then withinyr =1;&lt;BR /&gt; 	else if  startdate le reg_date and startdate le extdate then withingrace =1;&lt;BR /&gt; 		else  out = 1;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I was not thinking an ELSE was needed here, and I don't know if using ELSE is the right logic or not. That's really something you have to decide. Does it give you the expected answer?&lt;/P&gt;
&lt;DIV id="tap-translate"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="tap-translate"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Wed, 05 Feb 2020 01:43:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overlapping-dates/m-p/622334#M183063</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-02-05T01:43:59Z</dc:date>
    </item>
  </channel>
</rss>

