<?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 Using today() function in a where condition in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Using-today-function-in-a-where-condition/m-p/132472#M36037</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, I have the following SQL Code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let mydatepres = today() ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt; CREATE TABLE test AS SELECT histo.*&lt;/P&gt;&lt;P&gt; FROM ICOPLIB.histo AS histo&lt;/P&gt;&lt;P&gt; WHERE histo.reportproductiondate = &amp;amp;mydatepres&lt;/P&gt;&lt;P&gt;;QUIT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm having issue with the formatting of my variable in order to use it properly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What is the proper way to put today() function value in a variable and use it in a where statement?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My value histo.reportproduction is formatted datetime20.0&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your help and time&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 04 Nov 2013 16:48:29 GMT</pubDate>
    <dc:creator>nicnad</dc:creator>
    <dc:date>2013-11-04T16:48:29Z</dc:date>
    <item>
      <title>Using today() function in a where condition</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-today-function-in-a-where-condition/m-p/132472#M36037</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, I have the following SQL Code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let mydatepres = today() ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt; CREATE TABLE test AS SELECT histo.*&lt;/P&gt;&lt;P&gt; FROM ICOPLIB.histo AS histo&lt;/P&gt;&lt;P&gt; WHERE histo.reportproductiondate = &amp;amp;mydatepres&lt;/P&gt;&lt;P&gt;;QUIT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm having issue with the formatting of my variable in order to use it properly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What is the proper way to put today() function value in a variable and use it in a where statement?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My value histo.reportproduction is formatted datetime20.0&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your help and time&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Nov 2013 16:48:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-today-function-in-a-where-condition/m-p/132472#M36037</guid>
      <dc:creator>nicnad</dc:creator>
      <dc:date>2013-11-04T16:48:29Z</dc:date>
    </item>
    <item>
      <title>Re: Using today() function in a where condition</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-today-function-in-a-where-condition/m-p/132473#M36038</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 12pt;"&gt; %let mydatepres = &lt;SPAN style="color: #0000ff;"&gt;%sysfunc&lt;/SPAN&gt;(today(),date9.) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;CREATE TABLE test AS SELECT histo.*&lt;/P&gt;&lt;P&gt;FROM ICOPLIB.histo AS histo&lt;/P&gt;&lt;P&gt;WHERE datepart(histo.reportproductiondate) = "&amp;amp;mydatepres"d&lt;/P&gt;&lt;P&gt;;QUIT;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Nov 2013 16:55:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-today-function-in-a-where-condition/m-p/132473#M36038</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2013-11-04T16:55:29Z</dc:date>
    </item>
    <item>
      <title>Re: Using today() function in a where condition</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-today-function-in-a-where-condition/m-p/132474#M36039</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That would work if ICOPLIB is pointing to a SAS library.&lt;/P&gt;&lt;P&gt;If it is pointing to a database server using SAS/ACCESS then I do not think that SAS can pass the TODAY() function call into the database.&amp;nbsp; Instead try converting the TODAY() function result into a date literal.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;%let mydatepres = "%sysfunc(today(),date9.)"d ;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Nov 2013 16:58:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-today-function-in-a-where-condition/m-p/132474#M36039</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-11-04T16:58:22Z</dc:date>
    </item>
    <item>
      <title>Re: Using today() function in a where condition</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-today-function-in-a-where-condition/m-p/132475#M36040</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;and if the database presents the value as a timestamp, as @PaigeMiller suggests you could use the datetime() function instead of the today()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;WHERE&amp;nbsp; histo.reportproductiondate = "%sysfunc( datetime(), datetime)"dt &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 10pt; line-height: 1.5em;"&gt;that might be too accurate, so just try&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;WHERE&amp;nbsp; histo.reportproductiondate = "%sysfunc( date(), date):00:00:00"dt&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;I think it is likely that performing a datepart() function on a database variable&amp;nbsp; would perform less well than a function on a constant in the sas macro language environment.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Nov 2013 19:20:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-today-function-in-a-where-condition/m-p/132475#M36040</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2013-11-04T19:20:49Z</dc:date>
    </item>
    <item>
      <title>Re: Using today() function in a where condition</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-today-function-in-a-where-condition/m-p/132476#M36041</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;I think it is likely that performing a datepart() function on a database variable&amp;nbsp; would perform less well than a function on a constant in the sas macro language environment.&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;I don't understand this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;WHERE&amp;nbsp; histo.reportproductiondate = "%sysfunc( date(), date):00:00:00"dt&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;But this only matches histo.reportproductiondate that is exactly midnight (:00:00:00), and I'm guessing that the original request was to match any record in the database that had today's date.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Nov 2013 19:29:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-today-function-in-a-where-condition/m-p/132476#M36041</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2013-11-05T19:29:05Z</dc:date>
    </item>
    <item>
      <title>Re: Using today() function in a where condition</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-today-function-in-a-where-condition/m-p/132477#M36042</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To avoid applying a SAS function to the database table use the sql range operator BETWEEN&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;WHERE&amp;nbsp; histo.reportproductiondate BETWEEN "%sysfunc( date(), date):00:00:00"dt&amp;nbsp; AND "%sysfunc( date(), date):23:59:59"dt &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This ensures easy implementation of the WHERE clause inside the databse, to avoid having the whole table transferred to SAS to implement a SAS function&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Nov 2013 19:46:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-today-function-in-a-where-condition/m-p/132477#M36042</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2013-11-05T19:46:58Z</dc:date>
    </item>
  </channel>
</rss>

