<?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: using sysdate in queries in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/using-sysdate-in-queries/m-p/157900#M12303</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Something like below should do the job. It's using the SAS datetime() function to retrieve the current system datetime and it's using intnx() to shift this datetime value to the beginning of the previous day.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm using %sysfunc() to create a string containing the required datetime value so I then can used 'dt' to convert it to a datetime value. This way the SAS Access engine "knows" that it is dealing with a datetime value and will convert it to an appropriate data base SQL expression.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There might be easier way of doing this - but below is what I'm normally doing and where I know that it will work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've also added "options sastrace=",,,d" sastraceloc=saslog nostsuffix;"&lt;/P&gt;&lt;P&gt;Once you run the code against a data base these options will show you in the log what part of the SQL has been sent to the data base for processing. If the SAS Access engine wasn't able to translate everything then you might consider to re-formulate your SQL or to use explicit pass-through SQL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;&amp;nbsp; format dt dt_string_to_dt datetime21.;&lt;BR /&gt;&amp;nbsp; dt_string_to_dt="%sysfunc(intnx(dtday,%sysfunc(datetime()),-1,b),datetime21.)"dt;&lt;BR /&gt;&amp;nbsp; do i=-5 to 5;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dt=intnx('dtday',datetime(),i,'b');&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;options sastrace=",,,d" sastraceloc=saslog nostsuffix;&lt;BR /&gt;proc sql;&lt;BR /&gt;&amp;nbsp; create table want as&lt;BR /&gt;&amp;nbsp; select *&lt;BR /&gt;&amp;nbsp; from have&lt;BR /&gt;&amp;nbsp; where dt&amp;gt;="%sysfunc(intnx(dtday,%sysfunc(datetime()),-1,b),datetime21.)"dt&lt;BR /&gt;&amp;nbsp; ;&lt;BR /&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 28 Nov 2013 09:39:48 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2013-11-28T09:39:48Z</dc:date>
    <item>
      <title>using sysdate in queries</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/using-sysdate-in-queries/m-p/157895#M12298</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi i have a simple question, but i am unable to solve it &lt;/P&gt;&lt;P&gt;i just want to automize one of my queries and i need to change WHERE clause to System date -1 day. Is it possible in EG 5.1 using SYSDATE-1 instead of proper date &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;17&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CREATE TABLE WORK.SAMPLE_QUERY AS&lt;/P&gt;&lt;P&gt;18&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT t1.ID_NO,&lt;/P&gt;&lt;P&gt;19&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; t1.FIRST_DATE&lt;/P&gt;&lt;P&gt;20&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM O_C_OPR.DATABASEONE t1&lt;/P&gt;&lt;P&gt;21&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHERE t1.KREDI_TARIHI = &lt;SPAN style="color: #ffff00;"&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;SPAN style="color: #000000; text-decoration: underline;"&gt;'1Nov2013:3:0:0'dt&lt;/SPAN&gt;&lt;/SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you E&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Nov 2013 03:09:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/using-sysdate-in-queries/m-p/157895#M12298</guid>
      <dc:creator>omerzeybek</dc:creator>
      <dc:date>2013-11-28T03:09:23Z</dc:date>
    </item>
    <item>
      <title>Re: using sysdate in queries</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/using-sysdate-in-queries/m-p/157896#M12299</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do you want beginning of month, day before, or one second before the system datatime?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Nov 2013 03:48:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/using-sysdate-in-queries/m-p/157896#M12299</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2013-11-28T03:48:44Z</dc:date>
    </item>
    <item>
      <title>Re: using sysdate in queries</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/using-sysdate-in-queries/m-p/157897#M12300</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;All of Art's questions plus: Does this query run against a table in a database?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You probably wouldn't use &amp;amp;sysdate as this is the date when you started your SAS EG session. I would assume the solution will be something using datetime() together with intnx().&lt;/P&gt;&lt;P&gt;If the source table is in a database then you could create a datetime string so that the query gets pushed to the data base. Something like: "&amp;amp;datestring"d&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Assuming that you want to run the job overnight there is always midnight to be considered. So can you tell us between which times the job could possibly run and then which datetime value you want to pass to the where clause?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Nov 2013 04:25:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/using-sysdate-in-queries/m-p/157897#M12300</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2013-11-28T04:25:52Z</dc:date>
    </item>
    <item>
      <title>Re: using sysdate in queries</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/using-sysdate-in-queries/m-p/157898#M12301</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;of course. sorry for unspecific explanation &lt;/P&gt;&lt;P&gt;i need to find one day prior to last updated system date&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Nov 2013 06:45:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/using-sysdate-in-queries/m-p/157898#M12301</guid>
      <dc:creator>omerzeybek</dc:creator>
      <dc:date>2013-11-28T06:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: using sysdate in queries</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/using-sysdate-in-queries/m-p/157899#M12302</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes it is working&amp;nbsp; against a table in the database &lt;/P&gt;&lt;P&gt;i just need yo run program every morning&amp;nbsp; at 09:00 AM &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Nov 2013 06:48:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/using-sysdate-in-queries/m-p/157899#M12302</guid>
      <dc:creator>omerzeybek</dc:creator>
      <dc:date>2013-11-28T06:48:50Z</dc:date>
    </item>
    <item>
      <title>Re: using sysdate in queries</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/using-sysdate-in-queries/m-p/157900#M12303</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Something like below should do the job. It's using the SAS datetime() function to retrieve the current system datetime and it's using intnx() to shift this datetime value to the beginning of the previous day.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm using %sysfunc() to create a string containing the required datetime value so I then can used 'dt' to convert it to a datetime value. This way the SAS Access engine "knows" that it is dealing with a datetime value and will convert it to an appropriate data base SQL expression.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There might be easier way of doing this - but below is what I'm normally doing and where I know that it will work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've also added "options sastrace=",,,d" sastraceloc=saslog nostsuffix;"&lt;/P&gt;&lt;P&gt;Once you run the code against a data base these options will show you in the log what part of the SQL has been sent to the data base for processing. If the SAS Access engine wasn't able to translate everything then you might consider to re-formulate your SQL or to use explicit pass-through SQL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;&amp;nbsp; format dt dt_string_to_dt datetime21.;&lt;BR /&gt;&amp;nbsp; dt_string_to_dt="%sysfunc(intnx(dtday,%sysfunc(datetime()),-1,b),datetime21.)"dt;&lt;BR /&gt;&amp;nbsp; do i=-5 to 5;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dt=intnx('dtday',datetime(),i,'b');&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;options sastrace=",,,d" sastraceloc=saslog nostsuffix;&lt;BR /&gt;proc sql;&lt;BR /&gt;&amp;nbsp; create table want as&lt;BR /&gt;&amp;nbsp; select *&lt;BR /&gt;&amp;nbsp; from have&lt;BR /&gt;&amp;nbsp; where dt&amp;gt;="%sysfunc(intnx(dtday,%sysfunc(datetime()),-1,b),datetime21.)"dt&lt;BR /&gt;&amp;nbsp; ;&lt;BR /&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Nov 2013 09:39:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/using-sysdate-in-queries/m-p/157900#M12303</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2013-11-28T09:39:48Z</dc:date>
    </item>
  </channel>
</rss>

