<?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 Timestamp in SQL Query in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-Timestamp-in-SQL-Query/m-p/672972#M202328</link>
    <description>&lt;P&gt;Is that value part of the table name in an external database? As the name is&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;TableNameAsOf('2020-01-16 08:00:00')&lt;/LI-CODE&gt;
&lt;P&gt;with ( and ' : and space characters when you view the name in the external DB???&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might try referencing the name as&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;"TableNameAsOf('2020-01-16 08:00:00')"n&lt;/LI-CODE&gt;
&lt;P&gt;if it uses non-standard characters for SAS names. This may require the system setting of VALIDMEMNAME=Extend as well.&lt;/P&gt;</description>
    <pubDate>Tue, 28 Jul 2020 21:10:02 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-07-28T21:10:02Z</dc:date>
    <item>
      <title>Using Timestamp in SQL Query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Timestamp-in-SQL-Query/m-p/672970#M202327</link>
      <description>&lt;P&gt;I am using a table value function in sas code to pull back a database table as of a certain date.&amp;nbsp; The database uses a timestamp format of YYYY-MM-DD HH:MM:SS and SAS is not wanting to use that or any equivalent when actually running the query.&amp;nbsp; A sample is below.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table TableAsOf_Jan162020 as
     select * from Libname.TableNameAsOf('2020-01-16 08:00:00');
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I keep getting this error or something similar depending on the attempts at changing the format in the ( ).&lt;/P&gt;&lt;P&gt;ERROR: Invalid option name '2020-01-16 08:00:00'.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All help appreciated!&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2020 20:51:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Timestamp-in-SQL-Query/m-p/672970#M202327</guid>
      <dc:creator>altatunc</dc:creator>
      <dc:date>2020-07-28T20:51:15Z</dc:date>
    </item>
    <item>
      <title>Re: Using Timestamp in SQL Query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Timestamp-in-SQL-Query/m-p/672972#M202328</link>
      <description>&lt;P&gt;Is that value part of the table name in an external database? As the name is&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;TableNameAsOf('2020-01-16 08:00:00')&lt;/LI-CODE&gt;
&lt;P&gt;with ( and ' : and space characters when you view the name in the external DB???&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might try referencing the name as&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;"TableNameAsOf('2020-01-16 08:00:00')"n&lt;/LI-CODE&gt;
&lt;P&gt;if it uses non-standard characters for SAS names. This may require the system setting of VALIDMEMNAME=Extend as well.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2020 21:10:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Timestamp-in-SQL-Query/m-p/672972#M202328</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-07-28T21:10:02Z</dc:date>
    </item>
    <item>
      <title>Re: Using Timestamp in SQL Query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Timestamp-in-SQL-Query/m-p/672973#M202329</link>
      <description>&lt;P&gt;Assuming that SAS interprets your database timestamps as SAS datetimes (i.e. numbers), SAS/SQL will understand a query such as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table TableAsOf_Jan162020 as
select * 
from Libname.TableName
where timestamp &amp;lt;= '16JAN2020:08:00:00'dt;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If it sees them as strings you can get away with&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table TableAsOf_Jan162020 as
select * 
from Libname.TableName
where timestamp &amp;lt;= '2020-01-16 08:00:00';
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2020 21:09:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Timestamp-in-SQL-Query/m-p/672973#M202329</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-07-28T21:09:39Z</dc:date>
    </item>
    <item>
      <title>Re: Using Timestamp in SQL Query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Timestamp-in-SQL-Query/m-p/672974#M202330</link>
      <description>&lt;P&gt;Thanks for the question.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do not think so.&amp;nbsp; It is a table value function which returns another table as of that date value passed.&amp;nbsp; That other table is veiwable from the database (it is actually a table view though - i believe).&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2020 21:10:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Timestamp-in-SQL-Query/m-p/672974#M202330</guid>
      <dc:creator>altatunc</dc:creator>
      <dc:date>2020-07-28T21:10:42Z</dc:date>
    </item>
    <item>
      <title>Re: Using Timestamp in SQL Query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Timestamp-in-SQL-Query/m-p/672977#M202332</link>
      <description>&lt;P&gt;From our IT...in our case, Table Valued Functions take parameters and return data, much like a table or view: in this case there is a single parameter (called @AsOf) and it is a GMT timestamp. The function then returns exactly what the table looked like at the time provided.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2020 21:16:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Timestamp-in-SQL-Query/m-p/672977#M202332</guid>
      <dc:creator>altatunc</dc:creator>
      <dc:date>2020-07-28T21:16:03Z</dc:date>
    </item>
    <item>
      <title>Re: Using Timestamp in SQL Query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Timestamp-in-SQL-Query/m-p/673459#M202603</link>
      <description>&lt;P&gt;So, I contacted SAS Support and they provided a solution...&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P class="cs2654ae3a"&gt;&lt;FONT face="arial,helvetica,sans-serif" size="4"&gt;&lt;SPAN class="csedbfcf261"&gt;&lt;SPAN style="font-size: 8.0pt;"&gt;I looked through our database and found some old tracks where sites had to query Table Value Functions passed to the database and it looks like the only way this can work is to use PROC SQL explicit pass-through syntax. &amp;nbsp;I've included a link below to the section of documentation that discusses this method of connecting to databases via the SAS/ACCESS Interface to ODBC engine. &amp;nbsp;I also attempted to modify the basic syntax in this documentation with your specifics. &amp;nbsp;I think the query below should work with one modification. &amp;nbsp;You'll have to find the schema associated with the table in the database and replace schema with the actual schema name. &amp;nbsp;Explicit pass-through passes native database syntax over to the database for processing. &amp;nbsp;Since you have to reference tables with schema.tablename syntax in the database, this also needs to be used in when passing the query over from SAS:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class="cs2654ae3a"&gt;&lt;FONT face="arial,helvetica,sans-serif" size="4"&gt;&lt;SPAN class="csedbfcf261"&gt;&lt;SPAN style="font-size: 8.0pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class="cs2654ae3a"&gt;&lt;FONT face="arial,helvetica,sans-serif" size="4"&gt;&lt;SPAN class="csedbfcf261"&gt;&lt;SPAN style="font-size: 8.0pt;"&gt;SAS/ACCESS to ODBC explicit pass-through documentation: &amp;nbsp;&lt;A href="https://go.documentation.sas.com/?docsetId=acreldb&amp;amp;docsetTarget=p1f29m86u65hken1deqcybowtgma.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;&lt;SPAN class="cs951f5d7f1"&gt;https://go.documentation.sas.com/?docsetId=acreldb&amp;amp;docsetTarget=p1f29m86u65hken1deqcybowtgma.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/SPAN&gt;&lt;/A&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P class="cs2654ae3a"&gt;&lt;SPAN class="csedbfcf261"&gt;&lt;SPAN style="font-size: 8.0pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    connect to odbc (NOPROMPT=&amp;amp;DB READBUFF=100);
         create table TableAsOf_Jan162020 as
              select * from connection to odbc
                  ( select * from Schema/Libname.TableNameAsOf('2020-01-16 08:00:00') );
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P class="cs2654ae3a"&gt;Hope that helps anyone else in the same problem.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jul 2020 14:37:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Timestamp-in-SQL-Query/m-p/673459#M202603</guid>
      <dc:creator>altatunc</dc:creator>
      <dc:date>2020-07-30T14:37:16Z</dc:date>
    </item>
  </channel>
</rss>

