<?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 macro variables for date timestamp sql pass-thru to DB2 in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Using-macro-variables-for-date-timestamp-sql-pass-thru-to-DB2/m-p/44943#M11840</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Fairly new to SAS and trying to rewrite a messy, manual process code block and I have run into a problem that I have not been able to resolve.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I read a data set in from a csv file that contains 2 variables representing a table name and a corresponding timestamp.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So for example, record 1 would be:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;OECUSEML&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2012-03-22-10.49.18.283000&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I then run the following code to create global macro variables for each record.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;set Timestamps;&lt;/P&gt;&lt;P&gt;call symput (Table, DatetimeStamp);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This creates a global macro variable called &amp;amp;OECUSEML with the above timestamp value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I then am trying to reference this variable in the following code that connects to a DB2 database:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;create table OECUSEML&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; as select *&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from connection to odbc (&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select CUSNBER, ADDTYPCLF, EMLADR, SEQNBR,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int(replace(char(DATE(DATADD), ISO),'-','')) as DATADD,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EMLSRCCLF, LSTUPDJOB, LSTUPDPGM, LSTUPDUSR, LSTUPDNBR,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int(replace(char(DATE(LSTUPDTSP), ISO),'-','')) as LSTUP_DATE, TIME(LSTUPDTSP) as LSTUP_TIME,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LSTUPDTSP&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from PRDOTCDTA.OECUSEML&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where LSTUPDTSP &amp;gt; &amp;amp;OECUSEML);&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I get a SQL0104 - Token .18 was not valid error.&amp;nbsp; The variable is resolving to the correct value, but the where statement doesn't have single quotes around the value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I substitute the &amp;amp;OECUSEML variable with the actual '2012-03-22-10.49.18.283000' value including single quotes, it runs with the expected results.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I change the where clause, I get the following errors:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;where LSTUPDTSP &amp;gt; '&amp;amp;OECUSEML');&amp;nbsp;&amp;nbsp; -- SQL0180 - Syntax of timestamp value not valid.&lt;/P&gt;&lt;P&gt;where LSTUPDTSP &amp;gt; "&amp;amp;OECUSEML");&amp;nbsp; -- SQL0206 - Column "2012-03-22-10.49.18.283000" not in specified tables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need the where clause to pull the timestamp down to the milliseconds so I don't miss a records.&amp;nbsp; The purpose is to create a dynamic extract that can manage its own incrementals.&amp;nbsp; I have spent a lot of time pouring over the internet to try to find a solution to this problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any suggestions?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 27 Mar 2012 16:03:09 GMT</pubDate>
    <dc:creator>dburton</dc:creator>
    <dc:date>2012-03-27T16:03:09Z</dc:date>
    <item>
      <title>Using macro variables for date timestamp sql pass-thru to DB2</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-macro-variables-for-date-timestamp-sql-pass-thru-to-DB2/m-p/44943#M11840</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Fairly new to SAS and trying to rewrite a messy, manual process code block and I have run into a problem that I have not been able to resolve.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I read a data set in from a csv file that contains 2 variables representing a table name and a corresponding timestamp.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So for example, record 1 would be:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;OECUSEML&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2012-03-22-10.49.18.283000&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I then run the following code to create global macro variables for each record.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;set Timestamps;&lt;/P&gt;&lt;P&gt;call symput (Table, DatetimeStamp);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This creates a global macro variable called &amp;amp;OECUSEML with the above timestamp value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I then am trying to reference this variable in the following code that connects to a DB2 database:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;create table OECUSEML&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; as select *&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from connection to odbc (&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select CUSNBER, ADDTYPCLF, EMLADR, SEQNBR,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int(replace(char(DATE(DATADD), ISO),'-','')) as DATADD,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EMLSRCCLF, LSTUPDJOB, LSTUPDPGM, LSTUPDUSR, LSTUPDNBR,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int(replace(char(DATE(LSTUPDTSP), ISO),'-','')) as LSTUP_DATE, TIME(LSTUPDTSP) as LSTUP_TIME,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LSTUPDTSP&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from PRDOTCDTA.OECUSEML&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where LSTUPDTSP &amp;gt; &amp;amp;OECUSEML);&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I get a SQL0104 - Token .18 was not valid error.&amp;nbsp; The variable is resolving to the correct value, but the where statement doesn't have single quotes around the value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I substitute the &amp;amp;OECUSEML variable with the actual '2012-03-22-10.49.18.283000' value including single quotes, it runs with the expected results.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I change the where clause, I get the following errors:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;where LSTUPDTSP &amp;gt; '&amp;amp;OECUSEML');&amp;nbsp;&amp;nbsp; -- SQL0180 - Syntax of timestamp value not valid.&lt;/P&gt;&lt;P&gt;where LSTUPDTSP &amp;gt; "&amp;amp;OECUSEML");&amp;nbsp; -- SQL0206 - Column "2012-03-22-10.49.18.283000" not in specified tables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need the where clause to pull the timestamp down to the milliseconds so I don't miss a records.&amp;nbsp; The purpose is to create a dynamic extract that can manage its own incrementals.&amp;nbsp; I have spent a lot of time pouring over the internet to try to find a solution to this problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any suggestions?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Mar 2012 16:03:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-macro-variables-for-date-timestamp-sql-pass-thru-to-DB2/m-p/44943#M11840</guid>
      <dc:creator>dburton</dc:creator>
      <dc:date>2012-03-27T16:03:09Z</dc:date>
    </item>
    <item>
      <title>Using macro variables for date timestamp sql pass-thru to DB2</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-macro-variables-for-date-timestamp-sql-pass-thru-to-DB2/m-p/44944#M11841</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't have DB2, but, in reading your description of what you've tried, DB2 wants the datetime to have single quotes around it, and double won't work. If you put single quotes around your macro variable, SAS won't resolve it. If you put double quotes, it resolves, but DB2 complains. Catch-22.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's one way I can think of to single-quote a macro variable and still have it resolve. In between your datastep with the symput and the Proc SQL, insert the following statement:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let oecuseml = %str(%')&amp;amp;oecuseml%str(%');&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The contents of your macro variable are now: '2012-03-22-10.49.18/283000'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;See if that works.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Karl&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Mar 2012 17:12:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-macro-variables-for-date-timestamp-sql-pass-thru-to-DB2/m-p/44944#M11841</guid>
      <dc:creator>KarlK</dc:creator>
      <dc:date>2012-03-27T17:12:55Z</dc:date>
    </item>
    <item>
      <title>Using macro variables for date timestamp sql pass-thru to DB2</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-macro-variables-for-date-timestamp-sql-pass-thru-to-DB2/m-p/44945#M11842</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We've been using DB2 (z/OS mainframe) for years like this....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA _NULL_;&lt;/P&gt;&lt;P&gt;Set somedata; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DB2_DATE=EXTRACT_DATE;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CALL SYMPUT('DB2_DATE',"'"||PUT(DB2_DATE,YYMMDDD10.)||"'");&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SQL FEEDBACK ;&lt;/P&gt;&lt;P&gt;CREATE TABLE mytabel as&lt;/P&gt;&lt;P&gt;SELECT *&lt;/P&gt;&lt;P&gt;FROM CONNECTION TO DB2&lt;/P&gt;&lt;P&gt;(SELECT a bunch of fields &lt;/P&gt;&lt;P&gt;FROM&amp;nbsp;&amp;nbsp;&amp;nbsp; DB2.table&lt;/P&gt;&lt;P&gt;WHERE&amp;nbsp;&amp;nbsp; ACCOUNT IN ( &amp;amp;LIST )&amp;nbsp;&amp;nbsp;&amp;nbsp; AND&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A.DATE &amp;gt;= &amp;amp;DB2_DATE &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;);&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Mar 2012 17:28:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-macro-variables-for-date-timestamp-sql-pass-thru-to-DB2/m-p/44945#M11842</guid>
      <dc:creator>OS2Rules</dc:creator>
      <dc:date>2012-03-27T17:28:06Z</dc:date>
    </item>
    <item>
      <title>Using macro variables for date timestamp sql pass-thru to DB2</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-macro-variables-for-date-timestamp-sql-pass-thru-to-DB2/m-p/44946#M11843</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; This solution seems logical to me, but I had not run across the format YYMMDDD10. before.&amp;nbsp; When I run this, I get an ERROR 48-59: The format $YYMMDDD was not found or could not be loaded.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Mar 2012 17:47:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-macro-variables-for-date-timestamp-sql-pass-thru-to-DB2/m-p/44946#M11843</guid>
      <dc:creator>dburton</dc:creator>
      <dc:date>2012-03-27T17:47:50Z</dc:date>
    </item>
    <item>
      <title>Using macro variables for date timestamp sql pass-thru to DB2</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-macro-variables-for-date-timestamp-sql-pass-thru-to-DB2/m-p/44947#M11844</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; SUCCESS!!!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Using you logic, but simplifying it a little more I did this and it resolves correctly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;call symput (Table, "'"||DatetimeStamp||"'");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you both for your responses.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Mar 2012 18:03:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-macro-variables-for-date-timestamp-sql-pass-thru-to-DB2/m-p/44947#M11844</guid>
      <dc:creator>dburton</dc:creator>
      <dc:date>2012-03-27T18:03:43Z</dc:date>
    </item>
  </channel>
</rss>

