<?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 date macro variable in explicit pass through sql in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/date-macro-variable-in-explicit-pass-through-sql/m-p/324580#M9449</link>
    <description>&lt;P&gt;This Sql work fine:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;SELECT &lt;BR /&gt; TOP 10 * &lt;BR /&gt;FROM SomeCalendarData&lt;BR /&gt;WHERE SomeDate = '2016/01/01';&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So using a 'string macro variable' like so should work as well:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%let StartDate = 2016/01/01;

proc sql;
   connect to teradata 
    (BULKLOAD=YES MODE=TERADATA user=&amp;amp;user. Password=&amp;amp;passwd.);

   CREATE TABLE WorkTest.test AS
   select * from connection to teradata
   ( 
		SELECT 
			TOP 10 *      
		FROM SomeCalendarData
		WHERE SomeDate = %bquote('&amp;amp;StartDate.');
   ); 
quit;&lt;/PRE&gt;&lt;P&gt;Any idea why this is not the case? Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 13 Jan 2017 14:56:34 GMT</pubDate>
    <dc:creator>csetzkorn</dc:creator>
    <dc:date>2017-01-13T14:56:34Z</dc:date>
    <item>
      <title>date macro variable in explicit pass through sql</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/date-macro-variable-in-explicit-pass-through-sql/m-p/324580#M9449</link>
      <description>&lt;P&gt;This Sql work fine:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;SELECT &lt;BR /&gt; TOP 10 * &lt;BR /&gt;FROM SomeCalendarData&lt;BR /&gt;WHERE SomeDate = '2016/01/01';&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So using a 'string macro variable' like so should work as well:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%let StartDate = 2016/01/01;

proc sql;
   connect to teradata 
    (BULKLOAD=YES MODE=TERADATA user=&amp;amp;user. Password=&amp;amp;passwd.);

   CREATE TABLE WorkTest.test AS
   select * from connection to teradata
   ( 
		SELECT 
			TOP 10 *      
		FROM SomeCalendarData
		WHERE SomeDate = %bquote('&amp;amp;StartDate.');
   ); 
quit;&lt;/PRE&gt;&lt;P&gt;Any idea why this is not the case? Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2017 14:56:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/date-macro-variable-in-explicit-pass-through-sql/m-p/324580#M9449</guid>
      <dc:creator>csetzkorn</dc:creator>
      <dc:date>2017-01-13T14:56:34Z</dc:date>
    </item>
    <item>
      <title>Re: date macro variable in explicit pass through sql</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/date-macro-variable-in-explicit-pass-through-sql/m-p/324586#M9450</link>
      <description>&lt;P&gt;This line:&lt;/P&gt;
&lt;PRE&gt;		WHERE SomeDate = %bquote('&amp;amp;StartDate.');&lt;/PRE&gt;
&lt;P&gt;Your macro variable will not resolve unless its in doubel quotes:&lt;/P&gt;
&lt;PRE&gt;		WHERE SomeDate = %bquote("&amp;amp;StartDate.");
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2017 15:01:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/date-macro-variable-in-explicit-pass-through-sql/m-p/324586#M9450</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-01-13T15:01:21Z</dc:date>
    </item>
    <item>
      <title>Re: date macro variable in explicit pass through sql</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/date-macro-variable-in-explicit-pass-through-sql/m-p/324717#M9451</link>
      <description>&lt;P&gt;If Teradata doesn't like double quotes try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;WHERE SomeDate = %str(%')&amp;amp;StartDate.%str(%');&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Jan 2017 21:53:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/date-macro-variable-in-explicit-pass-through-sql/m-p/324717#M9451</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2017-01-13T21:53:16Z</dc:date>
    </item>
    <item>
      <title>Re: date macro variable in explicit pass through sql</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/date-macro-variable-in-explicit-pass-through-sql/m-p/324816#M9452</link>
      <description>After this I am getting: ERROR: Teradata prepare: A character string failed conversion to a numeric value. SQL statement was: SELECT TOP 10 * FROM&lt;BR /&gt;SomeCalendarData WHERE SomeDate = '2016/01/01';. This is a bit confusing as SELECT TOP 10 * FROM&lt;BR /&gt;SomeCalendarData WHERE SomeDate = '2016/01/01'; works fine in sql assistent when run against teradata. Any ideas?</description>
      <pubDate>Sat, 14 Jan 2017 11:12:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/date-macro-variable-in-explicit-pass-through-sql/m-p/324816#M9452</guid>
      <dc:creator>csetzkorn</dc:creator>
      <dc:date>2017-01-14T11:12:42Z</dc:date>
    </item>
    <item>
      <title>Re: date macro variable in explicit pass through sql</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/date-macro-variable-in-explicit-pass-through-sql/m-p/324817#M9453</link>
      <description>Sorry this does not work as terradata does not like the issued sql.</description>
      <pubDate>Sat, 14 Jan 2017 11:15:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/date-macro-variable-in-explicit-pass-through-sql/m-p/324817#M9453</guid>
      <dc:creator>csetzkorn</dc:creator>
      <dc:date>2017-01-14T11:15:25Z</dc:date>
    </item>
    <item>
      <title>Re: date macro variable in explicit pass through sql</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/date-macro-variable-in-explicit-pass-through-sql/m-p/324870#M9454</link>
      <description>&lt;P&gt;I've never used Teradata but a quick Google search for Teradata date formats suggests '2016-01-01' is more commonly used. Have you tried that?&lt;/P&gt;</description>
      <pubDate>Sun, 15 Jan 2017 06:01:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/date-macro-variable-in-explicit-pass-through-sql/m-p/324870#M9454</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2017-01-15T06:01:22Z</dc:date>
    </item>
    <item>
      <title>Re: date macro variable in explicit pass through sql</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/date-macro-variable-in-explicit-pass-through-sql/m-p/324886#M9455</link>
      <description>As i said: SELECT TOP 10 * FROM&lt;BR /&gt;SomeCalendarData WHERE SomeDate = '2016/01/01'; returns the expected results when I issue it from another teradata client (sql assistent) so I am a bit lost what's going on. Maybe SAS's explicit tries to be clever whilst causing issues.</description>
      <pubDate>Sun, 15 Jan 2017 13:53:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/date-macro-variable-in-explicit-pass-through-sql/m-p/324886#M9455</guid>
      <dc:creator>csetzkorn</dc:creator>
      <dc:date>2017-01-15T13:53:18Z</dc:date>
    </item>
    <item>
      <title>Re: date macro variable in explicit pass through sql</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/date-macro-variable-in-explicit-pass-through-sql/m-p/324887#M9456</link>
      <description>&lt;P&gt;Thanks for all your help, This:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%let StartDate = 2016/01/01;

proc sql;
   connect to teradata 
    (BULKLOAD=YES MODE=TERADATA user=&amp;amp;user. Password=&amp;amp;passwd.);

   CREATE TABLE WorkTest.test AS
   select * from connection to teradata
   ( 
		SELECT 
			TOP 10 *      
		FROM SomeCalendarData
		WHERE SomeDate = CAST(%bquote('&amp;amp;StartDate.') AS DATE FORMAT 'YYYY-MM-DD');
   ); 
quit;&lt;/PRE&gt;&lt;P&gt;Does the trick. Although I am still unsure why an explicit CAST like this should be necessary?! Bizare ...&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 15 Jan 2017 14:13:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/date-macro-variable-in-explicit-pass-through-sql/m-p/324887#M9456</guid>
      <dc:creator>csetzkorn</dc:creator>
      <dc:date>2017-01-15T14:13:36Z</dc:date>
    </item>
    <item>
      <title>Re: date macro variable in explicit pass through sql</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/date-macro-variable-in-explicit-pass-through-sql/m-p/324917#M9457</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/99946"&gt;@csetzkorn&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Although I am still unsure why an explicit CAST like this should be necessary?&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;According to docu that's the&amp;nbsp;syntax:&lt;/P&gt;
&lt;PRE&gt;CAST ( expression AS data_type [ ( length ) ] )&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;A href="https://msdn.microsoft.com/en-AU/library/ms187928.aspx#BKMK_examples" target="_blank"&gt;https://msdn.microsoft.com/en-AU/library/ms187928.aspx#BKMK_examples&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you just use the date string without any cast, then are you sure that this string gets converted to a SQL Server representation of DATE and not of DATETIME2 due to Data Type Precedence?&lt;/P&gt;
&lt;P&gt;&lt;A href="https://msdn.microsoft.com/en-us/library/ms190309.aspx" target="_blank"&gt;https://msdn.microsoft.com/en-us/library/ms190309.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd assume that if it becomes DATETIME2 then your code executes without any error but the where clause doesn't behave as you'd expected it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 15 Jan 2017 22:32:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/date-macro-variable-in-explicit-pass-through-sql/m-p/324917#M9457</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-01-15T22:32:03Z</dc:date>
    </item>
  </channel>
</rss>

