<?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: Calling Macro Generating Syntax Error in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674736#M203207</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The only time I use formatted dates or times in macro variables is when I get them from user prompts. And if I use them repeatedly in the code, I de-format them once at the beginning.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt; :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think we part ways a bit on this one.&amp;nbsp; In the case of date, time, or datetime values for macrovars, I typically keep them in the form they would otherwise have as literals, i.e.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;%let reference_date=06jun2019;&lt;BR /&gt;&amp;nbsp; or&lt;/LI&gt;
&lt;LI&gt;%let start_time= 23:01:35.356;&lt;BR /&gt;&amp;nbsp; or&lt;/LI&gt;
&lt;LI&gt;%let begin_point= &amp;amp;reference_date.:&amp;amp;start_time;&lt;BR /&gt;&amp;nbsp; or&lt;BR /&gt;%let begin_point=06jun2019:23:01:35.356;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;These expressions are easy for the user to read in any macro-generated code, yet they are also easy to use because they are ready-formatted for use in date, time, or datetime literals, as in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;&lt;BR /&gt;  set have;
   where event_date&amp;gt;="&amp;amp;reference_date"d;
   where evt_time&amp;gt;"&amp;amp;start_time"t;
   where event_dt&amp;gt;="&amp;amp;begin_point"dt:
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To me this is one of the primary benefits of the macro processor being allowed to resolve macro expressions in double quotes, while being prohibited from the same when in single quotes.&lt;/P&gt;</description>
    <pubDate>Wed, 05 Aug 2020 14:39:48 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2020-08-05T14:39:48Z</dc:date>
    <item>
      <title>Calling Macro Generating Syntax Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674417#M203091</link>
      <description>&lt;P&gt;Hello.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am having trouble trying to figure out why an error is generating when I am calling a macro that I created.&amp;nbsp; Here is what I am doing:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql; 
select max(export_created_date_time) format=datetime21.2
into :current_date_file_created
from msrflow.msrflow_dlytemp
;
quit;&lt;BR /&gt;&lt;BR /&gt;%put &amp;amp;current_date_file_created;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log file generates the datetime value of the macro&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;24 &lt;BR /&gt;25 %put &amp;amp;current_date_file_created;&lt;BR /&gt;03AUG2020:15:38:26.00&lt;BR /&gt;26&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am calling that macro in a simple query&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table data as
select
&amp;amp;current_date_file_created as date_file_created format=datetime21.2
from table1
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I get the following syntax error:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: Line generated by the macro variable "CURRENT_DATE_FILE_CREATED".
106         03AUG2020:15:38:26.00
              _______
              22
              76
3                                                          The SAS System                              09:28 Tuesday, August 4, 2020

&lt;FONT color="#FF0000"&gt;ERROR 22-322: Syntax error, expecting one of the following: a quoted string, !, !!, &amp;amp;, *, **, +, ',', -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?, 
              AND, AS, BETWEEN, CONTAINS, EQ, EQT, FORMAT, FROM, GE, GET, GT, GTT, IN, INFORMAT, INTO, IS, LABEL, LE, LEN, LENGTH, 
              LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, TRANSCODE, ^, ^=, |, ||, ~, ~=.  

ERROR 76-322: Syntax error, statement will be ignored.&lt;/FONT&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Any tips on what I am doing wrong?&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2020 16:08:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674417#M203091</guid>
      <dc:creator>elwayfan446</dc:creator>
      <dc:date>2020-08-04T16:08:49Z</dc:date>
    </item>
    <item>
      <title>Re: Calling Macro Generating Syntax Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674422#M203094</link>
      <description>&lt;P&gt;After the macro processor resolves the macro variable, you end up with this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table data as
select
03AUG2020:15:38:26.00 as date_file_created format=datetime21.2
from table1
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do you think this is valid syntax? If you think "no" (and SAS thinks "no"), look if you can find a way to make it valid.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hint: see &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lepg&amp;amp;docsetTarget=p1ugvn0mocff92n13mw9s56300jv.htm&amp;amp;locale=en#p0258wnlz15ubrn1vqfalp6l4hjz" target="_blank" rel="noopener"&gt;SAS Constants in Expressions&lt;/A&gt;, and Maxim 28.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2020 16:17:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674422#M203094</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-04T16:17:47Z</dc:date>
    </item>
    <item>
      <title>Re: Calling Macro Generating Syntax Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674424#M203096</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/24237"&gt;@elwayfan446&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Log file generates the datetime value of the macro&lt;/P&gt;
&lt;P&gt;24 &lt;BR /&gt;25 %put &amp;amp;current_date_file_created;&lt;BR /&gt;03AUG2020:15:38:26.00&lt;BR /&gt;26&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am calling that macro in a simple query&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table data as
select
&amp;amp;current_date_file_created as date_file_created format=datetime21.2
from table1
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I get the following syntax error:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: Line generated by the macro variable "CURRENT_DATE_FILE_CREATED".
106         03AUG2020:15:38:26.00
              _______
              22
              76
3                                                          The SAS System                              09:28 Tuesday, August 4, 2020

&lt;FONT color="#FF0000"&gt;ERROR 22-322: Syntax error, expecting one of the following: a quoted string, !, !!, &amp;amp;, *, **, +, ',', -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?, 
              AND, AS, BETWEEN, CONTAINS, EQ, EQT, FORMAT, FROM, GE, GET, GT, GTT, IN, INFORMAT, INTO, IS, LABEL, LE, LEN, LENGTH, 
              LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, TRANSCODE, ^, ^=, |, ||, ~, ~=.  

ERROR 76-322: Syntax error, statement will be ignored.&lt;/FONT&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Any tips on what I am doing wrong?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Using the value you report for the macrovar &amp;amp;&lt;CODE class=" language-sas"&gt;current_date_file_created&lt;/CODE&gt; generates this code in&amp;nbsp; you "create table data" statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  proc sql;
   create table data as
    select 03AUG2020:15:38:26.00 as date_file_created format=datetime21.2
   from table1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you really have a variable named 03AUG2020:15:38:26.00 (in which case the syntax should be "&amp;amp;current_date_file_created"n)?&amp;nbsp; I doubt it.&amp;nbsp; What are you trying to accomplish?&amp;nbsp; I.e. what do you want dataset DATE to contain?&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2020 16:21:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674424#M203096</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-08-04T16:21:08Z</dc:date>
    </item>
    <item>
      <title>Re: Calling Macro Generating Syntax Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674428#M203099</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp; I want that date to be the data pulled as the date_file_created in the proc sql; query.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2020 16:30:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674428#M203099</guid>
      <dc:creator>elwayfan446</dc:creator>
      <dc:date>2020-08-04T16:30:03Z</dc:date>
    </item>
    <item>
      <title>Re: Calling Macro Generating Syntax Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674430#M203100</link>
      <description>&lt;P&gt;So first write code that works without macro variables. Write code that works using the date/time&amp;nbsp;03AUG2020:15:38:26.00 hard coded. Once you have that working, then you should be able to create a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, just because you are using a macro variable does not mean you can ignore or avoid the syntax rules of whatever PROC you are using (in this case PROC SQL)&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2020 16:34:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674430#M203100</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-04T16:34:37Z</dc:date>
    </item>
    <item>
      <title>Re: Calling Macro Generating Syntax Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674431#M203101</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt; I have tried it as a datetime constant as well and get the following error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;, '&amp;amp;current_date_file_created'dt as DATE_FILE_CREATED format=datetime21.2
&lt;FONT color="#FF0000"&gt;ERROR: Invalid date/time/datetime constant '&amp;amp;current_date_file_created'dt.&lt;/FONT&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Aug 2020 16:34:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674431#M203101</guid>
      <dc:creator>elwayfan446</dc:creator>
      <dc:date>2020-08-04T16:34:58Z</dc:date>
    </item>
    <item>
      <title>Re: Calling Macro Generating Syntax Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674432#M203102</link>
      <description>&lt;P&gt;Are you trying to filter observations from table1, based on some datetime variable having the value "03AUG2020:15:38:26.00"dt?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so then you might want&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; create mytable as select * from table1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where some_variable="03AUG2020:15:38:26.00"dt ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will need to explain you purpose more clearly.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2020 16:35:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674432#M203102</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-08-04T16:35:56Z</dc:date>
    </item>
    <item>
      <title>Re: Calling Macro Generating Syntax Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674433#M203103</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/24237"&gt;@elwayfan446&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;The point the other 2 replies and SAS error message is attempting to make is 03AUG2020:15:38:26.00 is not a valid SAS variable name.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;I would recommend that you write the PROC SQL step first without the macro variable and get that working, then add the macro variable into the mix&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2020 16:36:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674433#M203103</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2020-08-04T16:36:17Z</dc:date>
    </item>
    <item>
      <title>Re: Calling Macro Generating Syntax Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674434#M203104</link>
      <description>&lt;P&gt;You have several options:&lt;/P&gt;
&lt;P&gt;1. correct use of a datetime literal&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql; 
select max(export_created_date_time) format=datetime21.2
into :current_date_file_created
from msrflow.msrflow_dlytemp
;
create table data as
select
"&amp;amp;current_date_file_created"dt as date_file_created format=datetime21.2
from table1
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;2. not using a format at all (Maxim 28!)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql; 
select max(export_created_date_time)
into :current_date_file_created
from msrflow.msrflow_dlytemp
;
create table data as
select
&amp;amp;current_date_file_created as date_file_created format=datetime21.2
from table1
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;3. not using a macro variable at all&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql; 
create table data as
select
  (select
    max(export_created_date_time)
    from msrflow.msrflow_dlytemp
  ) as date_file_created format=datetime21.2
from table1
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2020 16:38:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674434#M203104</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-04T16:38:59Z</dc:date>
    </item>
    <item>
      <title>Re: Calling Macro Generating Syntax Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674435#M203105</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/24237"&gt;@elwayfan446&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt; I have tried it as a datetime constant as well and get the following error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;, '&amp;amp;current_date_file_created'dt as DATE_FILE_CREATED format=datetime21.2
&lt;FONT color="#FF0000"&gt;ERROR: Invalid date/time/datetime constant '&amp;amp;current_date_file_created'dt.&lt;/FONT&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Macro variables are not resolved when enclosed with single quotes; use double quotes.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2020 16:39:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674435#M203105</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-04T16:39:53Z</dc:date>
    </item>
    <item>
      <title>Re: Calling Macro Generating Syntax Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674436#M203106</link>
      <description>&lt;P&gt;I have written the query without a variable and it works fine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table data as
select
ID
, exported_date as date_file_created
from table1
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results are:&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; date_file_created&lt;/P&gt;
&lt;P&gt;12487&amp;nbsp;&amp;nbsp;&amp;nbsp; 03AUG2020:15:38:26.00&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want the same results by calling the variable I have set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table data as
select
ID
, &amp;amp;current_date_file_created as date_file_created
from table1
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Aug 2020 16:41:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674436#M203106</guid>
      <dc:creator>elwayfan446</dc:creator>
      <dc:date>2020-08-04T16:41:22Z</dc:date>
    </item>
    <item>
      <title>Re: Calling Macro Generating Syntax Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674441#M203109</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my original post, this option is what I did and it gave me the error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;2. not using a format at all (Maxim 28!)

proc sql; 
select max(export_created_date_time)
into :current_date_file_created
from msrflow.msrflow_dlytemp
;
create table data as
select
&amp;amp;current_date_file_created as date_file_created format=datetime21.2
from table1
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However, I tried your option 1 and got the expected results!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;proc sql; 
select max(export_created_date_time) format=datetime21.2
into :current_date_file_created
from msrflow.msrflow_dlytemp
;
create table data as
select
"&amp;amp;current_date_file_created"dt as date_file_created format=datetime21.2
from table1
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Aug 2020 16:45:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674441#M203109</guid>
      <dc:creator>elwayfan446</dc:creator>
      <dc:date>2020-08-04T16:45:51Z</dc:date>
    </item>
    <item>
      <title>Re: Calling Macro Generating Syntax Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674445#M203113</link>
      <description>&lt;P&gt;Please post the whole log of your SQL steps where you received a syntax error. I am asking because this works:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data datetimes;
input dt datetime19.;
datalines;
03aug2020:18:43:00
;

proc sql noprint;
select max(dt) into :max_dt from datetimes;
create table want as select &amp;amp;max_dt. as max_dt format=datetime19.
from sashelp.class;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Aug 2020 16:52:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674445#M203113</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-04T16:52:09Z</dc:date>
    </item>
    <item>
      <title>Re: Calling Macro Generating Syntax Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674449#M203115</link>
      <description>&lt;P&gt;DO NOT FORMAT MACRO VARIABLES!!!!! Modifying your code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql; 
select max(export_created_date_time) /*format=datetime21.2*/ /* DO NOT FORMAT MACRO VARIABLES */
into :current_date_file_created
from msrflow.msrflow_dlytemp
;
create table data as
select
&amp;amp;current_date_file_created /* NO QUOTES NEEDED HERE, NO dt NEEDED ON THE END */&lt;BR /&gt;as date_file_created format=datetime21.2
from table1
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Aug 2020 16:55:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674449#M203115</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-04T16:55:51Z</dc:date>
    </item>
    <item>
      <title>Re: Calling Macro Generating Syntax Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674489#M203133</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt; no quotes was giving me the error.&amp;nbsp; Double quotes worked as noted in an answer above.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead of hitting me with the caps lock, can you explain why variables shouldn't be formatted so I (and others who find this thread) will know in the future?&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2020 18:09:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674489#M203133</guid>
      <dc:creator>elwayfan446</dc:creator>
      <dc:date>2020-08-04T18:09:42Z</dc:date>
    </item>
    <item>
      <title>Re: Calling Macro Generating Syntax Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674500#M203135</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/24237"&gt;@elwayfan446&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt; no quotes was giving me the error.&amp;nbsp; Double quotes worked as noted in an answer above.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No quotes and no formatting of the macro variables works fine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Formatting macro variables is not necessary for logic or arithmetic. SAS does all internal logic (such as comparing dates or date/times) on the unformatted values anway. So, to take a simple example, you can create a macro variable &amp;amp;datevar that is formatted as 01JAN2020, and then &lt;FONT face="courier new,courier"&gt;today()&amp;gt;"&amp;amp;datevar"d&lt;/FONT&gt; is the exact same thing as if the macro variable is unformatted and has value 21915 and then you use &lt;FONT face="courier new,courier"&gt;today()&amp;gt;&amp;amp;datevar&lt;/FONT&gt;. So there's extra programming work formatting the variable and then you have to un-format it by putting quotes around it and appending a d (for date values) or dt (for date/time values). I recommend you just avoid that extra work and use unformatted macro variables.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2020 18:38:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674500#M203135</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-04T18:38:39Z</dc:date>
    </item>
    <item>
      <title>Re: Calling Macro Generating Syntax Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674659#M203171</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/24237"&gt;@elwayfan446&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt; no quotes was giving me the error.&amp;nbsp; Double quotes worked as noted in an answer above.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead of hitting me with the caps lock, can you explain why variables shouldn't be formatted so I (and others who find this thread) will know in the future?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;hits you with capslock to get your attention, as you do not seem to actually run the codes we supply for proof.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once again, see my Maxim 28 (look at my footnotes for the link) for a short explanation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Keep in mind that resolving macro variables (and macros) only replaces &lt;EM&gt;text&lt;/EM&gt; and does nothing else. Wherever a raw value in code would be sufficient, use it in the macro variable, so you don't have to constantly think about correctly de-formatting a value when you reference the macrovar.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let mvar = %sysfunc(today());

%put &amp;amp;=mvar;

data _null_;
if &amp;amp;mvar = today()
then put "Yes!";
else put "No!";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Aug 2020 07:51:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674659#M203171</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-05T07:51:41Z</dc:date>
    </item>
    <item>
      <title>Re: Calling Macro Generating Syntax Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674716#M203196</link>
      <description>Perfect.  Thank you for the explanation.  I had always done it in the macro with no issues but will move away from that going forward.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 05 Aug 2020 13:34:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674716#M203196</guid>
      <dc:creator>elwayfan446</dc:creator>
      <dc:date>2020-08-05T13:34:12Z</dc:date>
    </item>
    <item>
      <title>Re: Calling Macro Generating Syntax Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674721#M203198</link>
      <description>&lt;P&gt;The only time I use formatted dates or times in macro variables is when I get them from user prompts. And if I use them repeatedly in the code, I de-format them once at the beginning.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Aug 2020 13:52:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674721#M203198</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-05T13:52:36Z</dc:date>
    </item>
    <item>
      <title>Re: Calling Macro Generating Syntax Error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674736#M203207</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The only time I use formatted dates or times in macro variables is when I get them from user prompts. And if I use them repeatedly in the code, I de-format them once at the beginning.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt; :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think we part ways a bit on this one.&amp;nbsp; In the case of date, time, or datetime values for macrovars, I typically keep them in the form they would otherwise have as literals, i.e.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;%let reference_date=06jun2019;&lt;BR /&gt;&amp;nbsp; or&lt;/LI&gt;
&lt;LI&gt;%let start_time= 23:01:35.356;&lt;BR /&gt;&amp;nbsp; or&lt;/LI&gt;
&lt;LI&gt;%let begin_point= &amp;amp;reference_date.:&amp;amp;start_time;&lt;BR /&gt;&amp;nbsp; or&lt;BR /&gt;%let begin_point=06jun2019:23:01:35.356;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;These expressions are easy for the user to read in any macro-generated code, yet they are also easy to use because they are ready-formatted for use in date, time, or datetime literals, as in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;&lt;BR /&gt;  set have;
   where event_date&amp;gt;="&amp;amp;reference_date"d;
   where evt_time&amp;gt;"&amp;amp;start_time"t;
   where event_dt&amp;gt;="&amp;amp;begin_point"dt:
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To me this is one of the primary benefits of the macro processor being allowed to resolve macro expressions in double quotes, while being prohibited from the same when in single quotes.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Aug 2020 14:39:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-Macro-Generating-Syntax-Error/m-p/674736#M203207</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-08-05T14:39:48Z</dc:date>
    </item>
  </channel>
</rss>

