<?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: Where condition in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Where-condition/m-p/392867#M25331</link>
    <description>&lt;P&gt;Is your END_DATE variable a character varaible? If so then how are you able to make a greater than or less than comparison between two values? &amp;nbsp;If your variable is coded to look like 'YYYY-MM-DD' then relative order will be preserved when comparing character versions of dates, but if you are using 'MM-DD-YYYY' or 'DD-MM-YYYY' or even 'ddMONyyyy' format then the order as character strings will not match the order as dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I assume you want to group your comparisons in this way so that you do not include every record with a missing end_date. Note the MISSING() function will work with both numeric and character variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;on (a.trading_group_id = b.trading_group_id)
 and ( (a.date_modified &amp;gt;= b.start_date
         and (a.date_modified &amp;lt; b.end_date or missing(end_date))
       )
     )
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your varaibles are actual date values then perhaps you can simplify using BETWEEN and COALESCE()? Use the -1 to make the upper bound comparison of the BETWEEN match the &amp;lt; used in your original query instead of &amp;lt;= that is normally used.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;on a.trading_group_id = b.trading_group_id
 and a.date_modified between b.start_date and coalesce(b.end_date,mdy(2099,1,1))-1
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 03 Sep 2017 17:41:23 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2017-09-03T17:41:23Z</dc:date>
    <item>
      <title>Where condition</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Where-condition/m-p/392817#M25328</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I looking at doing a left join with two tables. I have a data set 'X' that I want to left join to another data set where a trading group ID matches to data set 'Y' and the date modified from table 'X' is &amp;gt;= than start_date in table 'Y' and less than end_date in table 'Y' or end_date is blank.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope the above makes sense. Below is an attempt at a portion of the code to show you what I'm trying to do:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;on a.trading_group_id = b.&lt;SPAN&gt;trading_group_id and a.date_modified &amp;gt;= b.start_date and&amp;nbsp;a.date_modified&amp;nbsp;&amp;lt; end_date or end_date = '';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Not to sure on how to do this. Maybe a where data step first to order by dates.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any help is appreciated.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Sep 2017 23:50:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Where-condition/m-p/392817#M25328</guid>
      <dc:creator>Scott86</dc:creator>
      <dc:date>2017-09-02T23:50:22Z</dc:date>
    </item>
    <item>
      <title>Re: Where condition</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Where-condition/m-p/392825#M25329</link>
      <description>For this issue, I'll usually recode the blank end dates and make them 2099. &lt;BR /&gt;Then you can use the following, which is easier to follow IMO. &lt;BR /&gt;&lt;BR /&gt;And date between start_date and end_date&lt;BR /&gt;&lt;BR /&gt;One thing to make sure when you're dealing with multiple conditions is to enclose them with parentheses especially if you're mixing AND/OR logic.</description>
      <pubDate>Sun, 03 Sep 2017 01:03:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Where-condition/m-p/392825#M25329</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-03T01:03:10Z</dc:date>
    </item>
    <item>
      <title>Re: Where condition</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Where-condition/m-p/392846#M25330</link>
      <description>&lt;P&gt;Thanks Reeza that is a good tip.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Where should I be adding &lt;SPAN&gt;parentheses&lt;/SPAN&gt;?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please rewrite the code below with the &lt;SPAN&gt;parentheses&lt;/SPAN&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;on a.trading_group_id = b.&lt;/SPAN&gt;&lt;SPAN&gt;trading_group_id and a.date_modified &amp;gt;= b.start_date and&amp;nbsp;a.date_modified&amp;nbsp;&amp;lt; b.end_date or end_date = '';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks mate&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Sep 2017 05:41:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Where-condition/m-p/392846#M25330</guid>
      <dc:creator>Scott86</dc:creator>
      <dc:date>2017-09-03T05:41:46Z</dc:date>
    </item>
    <item>
      <title>Re: Where condition</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Where-condition/m-p/392867#M25331</link>
      <description>&lt;P&gt;Is your END_DATE variable a character varaible? If so then how are you able to make a greater than or less than comparison between two values? &amp;nbsp;If your variable is coded to look like 'YYYY-MM-DD' then relative order will be preserved when comparing character versions of dates, but if you are using 'MM-DD-YYYY' or 'DD-MM-YYYY' or even 'ddMONyyyy' format then the order as character strings will not match the order as dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I assume you want to group your comparisons in this way so that you do not include every record with a missing end_date. Note the MISSING() function will work with both numeric and character variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;on (a.trading_group_id = b.trading_group_id)
 and ( (a.date_modified &amp;gt;= b.start_date
         and (a.date_modified &amp;lt; b.end_date or missing(end_date))
       )
     )
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your varaibles are actual date values then perhaps you can simplify using BETWEEN and COALESCE()? Use the -1 to make the upper bound comparison of the BETWEEN match the &amp;lt; used in your original query instead of &amp;lt;= that is normally used.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;on a.trading_group_id = b.trading_group_id
 and a.date_modified between b.start_date and coalesce(b.end_date,mdy(2099,1,1))-1
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Sep 2017 17:41:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Where-condition/m-p/392867#M25331</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-09-03T17:41:23Z</dc:date>
    </item>
    <item>
      <title>Re: Where condition</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Where-condition/m-p/392908#M25333</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/135820"&gt;@Scott86&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please rewrite the code below with the &lt;SPAN&gt;parentheses&lt;/SPAN&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I don't know what logic you want....you do &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Make a small data set and test it out, which you should be doing anyways really.&lt;/P&gt;
&lt;P&gt;You can work with subsets of your data by using the OBS= option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;option obs=1000;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Sep 2017 03:31:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Where-condition/m-p/392908#M25333</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-04T03:31:18Z</dc:date>
    </item>
  </channel>
</rss>

