<?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 Searching for in between dates -comparing two methods in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Searching-for-in-between-dates-comparing-two-methods/m-p/289235#M269962</link>
    <description>&lt;P&gt;hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If searching for a date in between two dates, could someone offer a helpful tip (with explanation)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In example A, the following query worked and does yield desired results:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data mc_1 mc_2 mc_3 mc_4 mc_5 mc_6 mc_7 mc_8 ; set Have ;
if ts_acn_opn_dt&amp;lt;’01jan2010’d then output mc_1;
else if ts_acn_opn_dt&amp;gt;=‘01jan2010’d and ts_acn_opn_dt&amp;lt;’31dec2010’d then output mc_2;
else if ts_acn_opn_dt&amp;gt;=‘01jan2011’d and ts_acn_opn_dt&amp;lt;’31dec2011’d then output mc_3;
else if ts_acn_opn_dt&amp;gt;=‘01jan2012’d and ts_acn_opn_dt&amp;lt;’31dec2012’d then output mc_4;
else if ts_acn_opn_dt&amp;gt;=‘01jan2013’d and ts_acn_opn_dt&amp;lt;’31dec2013’d then output mc_5;
else if ts_acn_opn_dt&amp;gt;=‘01jan2014’d and ts_acn_opn_dt&amp;lt;’31dec2014’d then output mc_6;
else if  ts_acn_opn_dt&amp;gt;=‘01jan2015’d and ts_acn_opn_dt&amp;lt;’31dec2015’d then output mc_7;
else output mc_8;
run;&lt;/PRE&gt;&lt;P&gt;However, in example B, it does NOT yield desired result:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data mc_1 mc_2 mc_3 mc_4 mc_5 mc_6 mc_7 mc_8; set have ;
if ts_acn_opn_dt&amp;lt;’01jan2010’d then output mc_1; 
else if ’01jan2010’d&amp;gt;=ts_acn_opn_dt&amp;lt;’01jan2011’d then output mc_2; 
else if ‘01jan2011’d&amp;gt;=ts_acn_opn_dt&amp;lt;’01jan2012’d then output mc_3;
else if ‘01jan2012’d&amp;gt;=ts_acn_opn_dt&amp;lt;’01jan2013’d then output mc_4;
else if ‘01jan2013’d&amp;gt;=ts_acn_opn_dt&amp;lt;’01jan2014’d then output mc_5;
else if ‘01jan2014’d&amp;gt;=ts_acn_opn_dt&amp;lt;’01jan2015’d then output mc_6;
else if ‘01jan2015’d&amp;gt;=ts_acn_opn_dt&amp;lt;’01jan2016’d then output mc_7;
else output mc_8;run; &lt;/PRE&gt;&lt;P&gt;I'm trying to understand reason for example B not yielding the results I want (Output mc_3 contains observations dated 02jan2010).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
    <pubDate>Wed, 03 Aug 2016 14:14:30 GMT</pubDate>
    <dc:creator>brulard</dc:creator>
    <dc:date>2016-08-03T14:14:30Z</dc:date>
    <item>
      <title>Searching for in between dates -comparing two methods</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Searching-for-in-between-dates-comparing-two-methods/m-p/289235#M269962</link>
      <description>&lt;P&gt;hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If searching for a date in between two dates, could someone offer a helpful tip (with explanation)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In example A, the following query worked and does yield desired results:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data mc_1 mc_2 mc_3 mc_4 mc_5 mc_6 mc_7 mc_8 ; set Have ;
if ts_acn_opn_dt&amp;lt;’01jan2010’d then output mc_1;
else if ts_acn_opn_dt&amp;gt;=‘01jan2010’d and ts_acn_opn_dt&amp;lt;’31dec2010’d then output mc_2;
else if ts_acn_opn_dt&amp;gt;=‘01jan2011’d and ts_acn_opn_dt&amp;lt;’31dec2011’d then output mc_3;
else if ts_acn_opn_dt&amp;gt;=‘01jan2012’d and ts_acn_opn_dt&amp;lt;’31dec2012’d then output mc_4;
else if ts_acn_opn_dt&amp;gt;=‘01jan2013’d and ts_acn_opn_dt&amp;lt;’31dec2013’d then output mc_5;
else if ts_acn_opn_dt&amp;gt;=‘01jan2014’d and ts_acn_opn_dt&amp;lt;’31dec2014’d then output mc_6;
else if  ts_acn_opn_dt&amp;gt;=‘01jan2015’d and ts_acn_opn_dt&amp;lt;’31dec2015’d then output mc_7;
else output mc_8;
run;&lt;/PRE&gt;&lt;P&gt;However, in example B, it does NOT yield desired result:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data mc_1 mc_2 mc_3 mc_4 mc_5 mc_6 mc_7 mc_8; set have ;
if ts_acn_opn_dt&amp;lt;’01jan2010’d then output mc_1; 
else if ’01jan2010’d&amp;gt;=ts_acn_opn_dt&amp;lt;’01jan2011’d then output mc_2; 
else if ‘01jan2011’d&amp;gt;=ts_acn_opn_dt&amp;lt;’01jan2012’d then output mc_3;
else if ‘01jan2012’d&amp;gt;=ts_acn_opn_dt&amp;lt;’01jan2013’d then output mc_4;
else if ‘01jan2013’d&amp;gt;=ts_acn_opn_dt&amp;lt;’01jan2014’d then output mc_5;
else if ‘01jan2014’d&amp;gt;=ts_acn_opn_dt&amp;lt;’01jan2015’d then output mc_6;
else if ‘01jan2015’d&amp;gt;=ts_acn_opn_dt&amp;lt;’01jan2016’d then output mc_7;
else output mc_8;run; &lt;/PRE&gt;&lt;P&gt;I'm trying to understand reason for example B not yielding the results I want (Output mc_3 contains observations dated 02jan2010).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2016 14:14:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Searching-for-in-between-dates-comparing-two-methods/m-p/289235#M269962</guid>
      <dc:creator>brulard</dc:creator>
      <dc:date>2016-08-03T14:14:30Z</dc:date>
    </item>
    <item>
      <title>Re: Searching for in between dates -comparing two methods</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Searching-for-in-between-dates-comparing-two-methods/m-p/289238#M269963</link>
      <description>&lt;P&gt;Try either&lt;/P&gt;
&lt;P&gt;else if ’01jan2010’d&amp;gt;=ts_acn_opn_dt &amp;gt;=’31Dec2010’d&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in your specific case you could also use If year(ts_acn_opn_dt)=2010 then ...&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2016 14:22:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Searching-for-in-between-dates-comparing-two-methods/m-p/289238#M269963</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-08-03T14:22:26Z</dc:date>
    </item>
    <item>
      <title>Re: Searching for in between dates -comparing two methods</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Searching-for-in-between-dates-comparing-two-methods/m-p/289239#M269964</link>
      <description>&lt;P&gt;You moved your variable to the 'other' side of the comparison operator, &amp;gt;=, which means you need to flip the sign for the relationship to be true, to &amp;lt;=&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try changing your first set of operators from GE to LE.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You've changed your boundary values so you need to account for that.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2016 14:23:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Searching-for-in-between-dates-comparing-two-methods/m-p/289239#M269964</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-08-03T14:23:10Z</dc:date>
    </item>
    <item>
      <title>Re: Searching for in between dates -comparing two methods</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Searching-for-in-between-dates-comparing-two-methods/m-p/289244#M269965</link>
      <description>&lt;P&gt;thanks Reeza!&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2016 14:28:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Searching-for-in-between-dates-comparing-two-methods/m-p/289244#M269965</guid>
      <dc:creator>brulard</dc:creator>
      <dc:date>2016-08-03T14:28:20Z</dc:date>
    </item>
    <item>
      <title>Re: Searching for in between dates -comparing two methods</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Searching-for-in-between-dates-comparing-two-methods/m-p/289245#M269966</link>
      <description>&lt;P&gt;thanks Ballardw for showing this helpful tip: If year(ts_acn_opn_dt)=2010 then&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2016 14:29:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Searching-for-in-between-dates-comparing-two-methods/m-p/289245#M269966</guid>
      <dc:creator>brulard</dc:creator>
      <dc:date>2016-08-03T14:29:47Z</dc:date>
    </item>
  </channel>
</rss>

