<?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: ERROR: Teradata prepare:macro variable dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/ERROR-Teradata-prepare-macro-variable-dates/m-p/603002#M174660</link>
    <description>Thank you, I tried that. But got the same error.</description>
    <pubDate>Sat, 09 Nov 2019 18:03:33 GMT</pubDate>
    <dc:creator>AJ_Brien</dc:creator>
    <dc:date>2019-11-09T18:03:33Z</dc:date>
    <item>
      <title>ERROR: Teradata prepare:macro variable dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-Teradata-prepare-macro-variable-dates/m-p/603000#M174658</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I initialized the following macro variables such that these are their formats:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let&amp;nbsp;cycles= 9; /*this is num 6.*/&lt;/P&gt;&lt;P&gt;%let cycle_dates = 09NOV2019; /*this is date9.*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;using these I'm trying to pull data from teradata:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc SQL;
CONNECT TO teradata (user="%sysget(USER)" password="xx." tdpid=xx mode=teradata); 

CREATE TABLE abc AS Select * From connection to teradata

(SELECT top 10 * FROM xx
where CYCL IN (&amp;amp;cycles.) and CYCL_DT IN (&amp;amp;cycle_dates.) );

DISCONNECT FROM TERADATA;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the formats for teradata variables are as follows:&lt;/P&gt;&lt;P&gt;CYCL: num 11.&lt;/P&gt;&lt;P&gt;CYCL_DT: date9.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am getting this error even though the formats match:&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;ERROR:&lt;/STRONG&gt; &lt;/U&gt;Teradata prepare: Syntax error, expected something like an 'OR' keyword or a 'TO' keyword or ',' between an integer and the&lt;BR /&gt;word 'NOV2019'. SQL statement was: SELECT top 10 * FROM xx&lt;BR /&gt;where CYCL IN &amp;nbsp;(9) and CYCL_DT IN (09NOV2019).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;there are no other notes or warning messages with this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would appreciate helping me understand what I'm doing wrong.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Nov 2019 17:49:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-Teradata-prepare-macro-variable-dates/m-p/603000#M174658</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2019-11-09T17:49:12Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: Teradata prepare:macro variable dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-Teradata-prepare-macro-variable-dates/m-p/603001#M174659</link>
      <description>&lt;P&gt;Try the below syntax for selecting 10 records from Teradata.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Proc SQL;
CONNECT TO teradata (user="%sysget(USER)" password="xx." tdpid=xx mode=teradata); 

CREATE TABLE abc AS Select * From connection to teradata

(SELECT  * FROM xx
where CYCL IN (&amp;amp;cycles.) and CYCL_DT IN (&amp;amp;cycle_dates.) 
&lt;STRONG&gt;&lt;FONT color="#800000"&gt;sample 10&lt;/FONT&gt;&lt;/STRONG&gt;
);

DISCONNECT FROM TERADATA;
QUIT;&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Nov 2019 17:57:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-Teradata-prepare-macro-variable-dates/m-p/603001#M174659</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2019-11-09T17:57:00Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: Teradata prepare:macro variable dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-Teradata-prepare-macro-variable-dates/m-p/603002#M174660</link>
      <description>Thank you, I tried that. But got the same error.</description>
      <pubDate>Sat, 09 Nov 2019 18:03:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-Teradata-prepare-macro-variable-dates/m-p/603002#M174660</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2019-11-09T18:03:33Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: Teradata prepare:macro variable dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-Teradata-prepare-macro-variable-dates/m-p/603003#M174661</link>
      <description>&lt;P&gt;You are setting the macro variable cycle_dates to a string that looks like how SAS would PRINT the value of a date variable (IF the DATE9. format was attached to it.).&amp;nbsp; You could use that in SAS code if you enclosed it in quotes and added the letter D so that is recognized as a date literal.&amp;nbsp; SAS requires that the quoted string used in a date literal is valid for the DATE INformat.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you are using it to generate part of your Teradata code you want the macro variable to have a string that looks like how Teradata would expect your to represent a date value in code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let cycle_dates = '2019-11-09' ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Nov 2019 18:31:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-Teradata-prepare-macro-variable-dates/m-p/603003#M174661</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-11-09T18:31:38Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: Teradata prepare:macro variable dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-Teradata-prepare-macro-variable-dates/m-p/603004#M174662</link>
      <description>&lt;P&gt;See if the code runs without the macro variables first.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Proc SQL;
CONNECT TO teradata (user="%sysget(USER)" password="xx." tdpid=xx mode=teradata); 

CREATE TABLE abc AS Select * From connection to teradata

(SELECT  * FROM xx
where CYCL =9
 and CYCL_DT ='2019-11-09'
sample 10
);

DISCONNECT FROM TERADATA;
QUIT;&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Nov 2019 18:29:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-Teradata-prepare-macro-variable-dates/m-p/603004#M174662</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2019-11-09T18:29:53Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: Teradata prepare:macro variable dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-Teradata-prepare-macro-variable-dates/m-p/603033#M174681</link>
      <description>Thank you for your reply. I tried the following:&lt;BR /&gt;&lt;BR /&gt;Proc SQL;&lt;BR /&gt;CONNECT TO teradata (user="%sysget(USER)" password="xx" tdpid=xx mode=teradata);&lt;BR /&gt;CREATE TABLE WORK.Bacardi AS&lt;BR /&gt;Select * From connection to teradata&lt;BR /&gt;(SELECT top 10 * FROM xx&lt;BR /&gt;where CYCL_NO IN (9) and CYCL_DT IN ('09NOV2019'd));&lt;BR /&gt;DISCONNECT FROM TERADATA;&lt;BR /&gt;QUIT;&lt;BR /&gt;&lt;BR /&gt;that gave me this error:&lt;BR /&gt;ERROR: Teradata prepare: Syntax error, expected something like an 'OR' keyword or a 'TO' keyword or ',' between a string or a&lt;BR /&gt;Unicode character literal and the word 'd'.&lt;BR /&gt;&lt;BR /&gt;The format of CYCL_DT in the teradata table is num date9.&lt;BR /&gt;Is that not the format I'm passing this in? The CYCL_DT values in the table look like these:&lt;BR /&gt;09NOV2019&lt;BR /&gt;10NOV2019......&lt;BR /&gt;&lt;BR /&gt;I then tried changing to this: CYCL_DT IN ('2019-11-09'd))&lt;BR /&gt;&lt;BR /&gt;But I still got the same error.&lt;BR /&gt;&lt;BR /&gt;I then did this: CYCL_DT IN ("2019-11-09"d)), so I got really random results and the warning message: WARNING: This SAS global statement is not supported in PROC SQL. It has been ignored.&lt;BR /&gt;</description>
      <pubDate>Sun, 10 Nov 2019 03:19:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-Teradata-prepare-macro-variable-dates/m-p/603033#M174681</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2019-11-10T03:19:36Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: Teradata prepare:macro variable dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-Teradata-prepare-macro-variable-dates/m-p/603035#M174682</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265086"&gt;@AJ_Brien&lt;/a&gt;&amp;nbsp;Since you are using the Pass through facility to Teradata the SAS Syntax is not valid within the Query (Between connect and Disconnect statements).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;where CYCL_NO IN (9) and CYCL_DT IN (&lt;STRIKE&gt;&lt;FONT color="#993300"&gt;'09NOV2019'd&lt;/FONT&gt;&lt;/STRIKE&gt;));&lt;/PRE&gt;&lt;P&gt;When you are attempting to open the data residing in Teradata using a Library within the client, SAS tries to apply its native formats&amp;nbsp; to display the data in the best possible way.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However in your case the query is passed to the Teradata in its original form so you cannot apply the sas constructs within the query.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please try this syntax and see if it works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;where CYCL in (9)  and CYCL_DT in ('2019-11-09')&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You may also consider changing your query to make use of the SAS Formats , here is an example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;libname teralib teradata server=&lt;/SPAN&gt;&lt;I&gt;server&lt;/I&gt;&lt;SPAN&gt; user=&lt;/SPAN&gt;&lt;I&gt;userid&lt;/I&gt;&lt;SPAN&gt; pwd=&lt;/SPAN&gt;&lt;I&gt;password&lt;/I&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Proc SQL;
CREATE TABLE WORK.Bacardi AS
SELECT * FROM teralib.xx(obs=10)
where CYCL_NO IN (9) and CYCL_DT IN ('09NOV2019'd));
QUIT;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Nov 2019 03:51:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-Teradata-prepare-macro-variable-dates/m-p/603035#M174682</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2019-11-10T03:51:32Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: Teradata prepare:macro variable dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-Teradata-prepare-macro-variable-dates/m-p/603037#M174684</link>
      <description>Thank you for your input, I really appreciate the guidance.&lt;BR /&gt;&lt;BR /&gt;I tried doing this: where CYCL in (9) and CYCL_DT in ('2019-11-09')&lt;BR /&gt;&lt;BR /&gt;but I end up getting random results, seems like my where condition is completely ignored. I only get this warning, and no errors or notes:&lt;BR /&gt;&lt;BR /&gt;where CYCL_NO IN (9) and CYCL_DT IN ('2019-11-09'));&lt;BR /&gt;WARNING: This SAS global statement is not supported in PROC SQL. It has been ignored.&lt;BR /&gt;&lt;BR /&gt;The issue is definitely in the CYCL_DT condition because just doing the CYCL_NO alone works.&lt;BR /&gt;&lt;BR /&gt;I have a bunch of code written using pass through, hence preferred following the same method for this query too.</description>
      <pubDate>Sun, 10 Nov 2019 04:23:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-Teradata-prepare-macro-variable-dates/m-p/603037#M174684</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2019-11-10T04:23:58Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: Teradata prepare:macro variable dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-Teradata-prepare-macro-variable-dates/m-p/603042#M174687</link>
      <description>&lt;P&gt;You have an extra closing round bracket at the end of your WHERE statement that possibly shouldn't be there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also please post complete SAS logs of your source code AND notes and errors. You are making it hard for us to see what is going on when you post just the bits you think are the problem.&lt;/P&gt;</description>
      <pubDate>Sun, 10 Nov 2019 04:51:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-Teradata-prepare-macro-variable-dates/m-p/603042#M174687</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-11-10T04:51:06Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: Teradata prepare:macro variable dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-Teradata-prepare-macro-variable-dates/m-p/603058#M174693</link>
      <description>&lt;P&gt;You can't just stick a random WHERE statement it the middle of no where.&amp;nbsp; And you cannot use Teradata style date literals outside of the code that you are explicitly sending to Teradata.&lt;/P&gt;</description>
      <pubDate>Sun, 10 Nov 2019 14:07:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-Teradata-prepare-macro-variable-dates/m-p/603058#M174693</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-11-10T14:07:56Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR: Teradata prepare:macro variable dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-Teradata-prepare-macro-variable-dates/m-p/603969#M175034</link>
      <description>&lt;P&gt;Thank you all for help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Turned out there was an issue on my SAS teradata connect which is why the date even in the right format wasn't going through.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciate everyone's input. Thank you so much &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Nov 2019 20:50:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-Teradata-prepare-macro-variable-dates/m-p/603969#M175034</guid>
      <dc:creator>AJ_Brien</dc:creator>
      <dc:date>2019-11-13T20:50:53Z</dc:date>
    </item>
  </channel>
</rss>

