<?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: Proc SQL - Where ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Where/m-p/545926#M151104</link>
    <description>&lt;P&gt;Awesome!&amp;nbsp; Thanks much, Tom!&lt;/P&gt;</description>
    <pubDate>Mon, 25 Mar 2019 19:00:12 GMT</pubDate>
    <dc:creator>ybz12003</dc:creator>
    <dc:date>2019-03-25T19:00:12Z</dc:date>
    <item>
      <title>Proc SQL - Where ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Where/m-p/545915#M151097</link>
      <description>&lt;P&gt;Hello:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have some codes from the past (see the end).&amp;nbsp;&amp;nbsp; I would like to modify the following codes as my request below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1.&amp;nbsp; Bloodculture = 1 and CultureDate ^=. ( Must have)&lt;/P&gt;
&lt;P&gt;2.&amp;nbsp; When AdmitDate is not missing, CultureDate less than AdmitDate . (Option 1)&lt;/P&gt;
&lt;P&gt;3.&amp;nbsp; When DischargeDate is not missing, CultureDate less than DischargeDate . (Option 2)&lt;/P&gt;
&lt;P&gt;4.&amp;nbsp; When ERAdmitDate is not missing, CultureDate less than ERAdmitDate . (Option 3)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have over 30 similar codes using PROC SQL to do the inquiry.&amp;nbsp;&amp;nbsp; Therefore, I am ONLY looking for using 'PROC SQL WHERE' to do this task.&amp;nbsp;&amp;nbsp; Could someone help me how to modify the codes below and meet the requirement.&amp;nbsp;&amp;nbsp; Thank you.&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;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table Want as
 	select site, id, culturedate, dischargedate, admitdate,ERadmitdate, bloodculture
 	from have
 	where bloodculture = 1 and culturedate ^= . or (culturedate lt admitdate-1 and admitdate ne .) or (culturedate gt dischargedate and dischargedate ne .) 
			or (culturedate lt EDadmitdate-1 and EDadmitdate ne .)
 	order by site, id;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Mar 2019 18:14:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Where/m-p/545915#M151097</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2019-03-25T18:14:52Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - Where ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Where/m-p/545916#M151098</link>
      <description>&lt;P&gt;Here's the overall format for the WHERE clause.&amp;nbsp; You will need to supply the correct logic for each option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where bloodculture = 1 and culturedate ne . and
   ( (logic for option 1) or
     (logic for option 2) or
     (logic for option 3)
   )&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Mar 2019 18:23:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Where/m-p/545916#M151098</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-03-25T18:23:00Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - Where ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Where/m-p/545919#M151100</link>
      <description>&lt;P&gt;Don't mix AND and OR without proper grouping or you won't get what you want.&lt;/P&gt;
&lt;P&gt;Do you want this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where bloodculture = 1
  and culturedate ^= . 
  AND ( (culturedate lt admitdate-1 and admitdate ne .)
     or (culturedate gt dischargedate and dischargedate ne .)
     or (culturedate lt EDadmitdate-1 and EDadmitdate ne .)
      )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where ( bloodculture = 1
    and culturedate ^= . 
      )
  OR  ( (culturedate lt admitdate-1 and admitdate ne .)
     or (culturedate gt dischargedate and dischargedate ne .)
     or (culturedate lt EDadmitdate-1 and EDadmitdate ne .)
      )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2019 18:40:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Where/m-p/545919#M151100</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-03-25T18:40:20Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - Where ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Where/m-p/545921#M151101</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table Want as
select 
    site, 
    id, 
    cultureDate, 
    dischargeDate, 
    EDadmitDate, 
    ERadmitDate, 
    bloodCulture
from have
where 
    bloodCulture = 1 and 
    cultureDate is not missing and
    cultureDate &amp;lt; max(EDadmitDate, dischargeDate, ERadmitDate)
order by site, id;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Mar 2019 18:47:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Where/m-p/545921#M151101</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-03-25T18:47:34Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - Where ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Where/m-p/545926#M151104</link>
      <description>&lt;P&gt;Awesome!&amp;nbsp; Thanks much, Tom!&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2019 19:00:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Where/m-p/545926#M151104</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2019-03-25T19:00:12Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - Where ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Where/m-p/545971#M151124</link>
      <description>&lt;P&gt;Warning: Subsetting conditions involving OR clauses are handled inefficiently by SAS SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sometimes, such logical conditions can't be avoided. But sometimes they can. See above.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2019 21:59:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-Where/m-p/545971#M151124</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-03-25T21:59:04Z</dc:date>
    </item>
  </channel>
</rss>

