<?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: Passing Datetime into a SAS query using MACROS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Passing-Datetime-into-a-SAS-query-using-MACROS/m-p/770345#M244391</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/279632"&gt;@PrudhviB&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi SAS Experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to pass datetime value into a sas query and its not working for me.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;here is my query and any help is appreciated.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;MACRO:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;%let today = %sysfunc(today());&lt;/P&gt;
&lt;P&gt;%let NEXT_DAY_1 = %sysfunc(dhms(%sysfunc(intnx(day,&amp;amp;today,-2)),0,0,0));&lt;BR /&gt;%put &amp;amp;NEXT_DAY_1;&lt;/P&gt;
&lt;P&gt;%let x= %sysfunc(putn(&amp;amp;NEXT_DAY_1, datetime.));&lt;BR /&gt;%put &amp;amp;x;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;O/P:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;22SEP21:00:00:00&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;SAS Query&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;this is where i am passing the macro date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;WHERE t1.CALENDAR_WK_ENDING_DATE = &amp;amp;x;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;ERROR:&lt;/STRONG&gt;&lt;/U&gt;&lt;BR /&gt;NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;BR /&gt;NOTE: Line generated by the macro variable "X".&lt;BR /&gt;80 18SEP21:00:00:00&lt;BR /&gt;_____&lt;BR /&gt;22&lt;BR /&gt;76&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: ;, !, !!, &amp;amp;, *, **, +, -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, AND, EQ, EQT, EXCEPT, &lt;BR /&gt;GE, GET, GROUP, GT, GTT, HAVING, INTERSECT, LE, LET, LT, LTT, NE, NET, NOT, OR, ORDER, OUTER, UNION, ^, ^=, |, ||, ~, &lt;BR /&gt;~=.&lt;/P&gt;
&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;it takes this format for some reason.&amp;nbsp;&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;'13Sep2021:0:0:0'dt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The code you use:&lt;/P&gt;
&lt;PRE&gt;WHERE t1.CALENDAR_WK_ENDING_DATE = &amp;amp;x;&lt;/PRE&gt;
&lt;P&gt;Would resolve to&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;WHERE t1.CALENDAR_WK_ENDING_DATE = 22SEP21:00:00:00;&lt;/PRE&gt;
&lt;P&gt;Which is not legal syntax and throws the error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is NO reason to use the formatted value.&lt;/P&gt;
&lt;P&gt;Use&lt;/P&gt;
&lt;PRE&gt;WHERE t1.CALENDAR_WK_ENDING_DATE = &amp;amp;NEXT_DAY_1;&lt;/PRE&gt;
&lt;P&gt;The value would resolve to the numeric datetime value and not throw any error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;'13Sep2021:0:0:0'dt;&lt;/PRE&gt;
&lt;P&gt;works because that is a datetime literal. And if you use similar code with the macro and examine that datetime literal the numeric values are the same: (running on 24Sep2021)&lt;/P&gt;
&lt;PRE&gt;461  %let today = %sysfunc(today());
462
463  %let NEXT_DAY_1 = %sysfunc(dhms(%sysfunc(intnx(day,&amp;amp;today,-2)),0,0,0));
464  %put Nex_date is: &amp;amp;NEXT_DAY_1;
Nex_date is: &lt;FONT size="5" color="#0000FF"&gt;&lt;STRONG&gt;1947888000&lt;/STRONG&gt;&lt;/FONT&gt;
465
466  data _null_;
467     x=intnx('dtday', '24Sep2021:0:0:0'dt,-2);
468     put x= ;
469  run;

x=&lt;FONT size="5" color="#FF00FF"&gt;&lt;STRONG&gt;1947888000
&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;An example of why formatting date, time or datetime values in macro variables in code for manipulations is not a good idea. Use the numeric value and keep the formatted values for text like titles and file names that people read.&lt;/P&gt;</description>
    <pubDate>Fri, 24 Sep 2021 19:34:46 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-09-24T19:34:46Z</dc:date>
    <item>
      <title>Passing Datetime into a SAS query using MACROS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-Datetime-into-a-SAS-query-using-MACROS/m-p/770340#M244388</link>
      <description>&lt;P&gt;Hi SAS Experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to pass datetime value into a sas query and its not working for me.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;here is my query and any help is appreciated.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;MACRO:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;%let today = %sysfunc(today());&lt;/P&gt;
&lt;P&gt;%let NEXT_DAY_1 = %sysfunc(dhms(%sysfunc(intnx(day,&amp;amp;today,-2)),0,0,0));&lt;BR /&gt;%put &amp;amp;NEXT_DAY_1;&lt;/P&gt;
&lt;P&gt;%let x= %sysfunc(putn(&amp;amp;NEXT_DAY_1, datetime.));&lt;BR /&gt;%put &amp;amp;x;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;O/P:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;22SEP21:00:00:00&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;SAS Query&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;this is where i am passing the macro date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;WHERE t1.CALENDAR_WK_ENDING_DATE = &amp;amp;x;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;ERROR:&lt;/STRONG&gt;&lt;/U&gt;&lt;BR /&gt;NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;BR /&gt;NOTE: Line generated by the macro variable "X".&lt;BR /&gt;80 18SEP21:00:00:00&lt;BR /&gt;_____&lt;BR /&gt;22&lt;BR /&gt;76&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: ;, !, !!, &amp;amp;, *, **, +, -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, AND, EQ, EQT, EXCEPT, &lt;BR /&gt;GE, GET, GROUP, GT, GTT, HAVING, INTERSECT, LE, LET, LT, LTT, NE, NET, NOT, OR, ORDER, OUTER, UNION, ^, ^=, |, ||, ~, &lt;BR /&gt;~=.&lt;/P&gt;
&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;it takes this format for some reason.&amp;nbsp;&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;'13Sep2021:0:0:0'dt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Sep 2021 18:47:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-Datetime-into-a-SAS-query-using-MACROS/m-p/770340#M244388</guid>
      <dc:creator>PrudhviB</dc:creator>
      <dc:date>2021-09-24T18:47:57Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Datetime into a SAS query using MACROS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-Datetime-into-a-SAS-query-using-MACROS/m-p/770343#M244389</link>
      <description>&lt;P&gt;Show us the entire macro and PROC SQL code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Show us the entire LOG from running this code.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Sep 2021 18:55:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-Datetime-into-a-SAS-query-using-MACROS/m-p/770343#M244389</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-09-24T18:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Datetime into a SAS query using MACROS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-Datetime-into-a-SAS-query-using-MACROS/m-p/770344#M244390</link>
      <description>here is the details i have edited some sensitive data. &lt;BR /&gt;&lt;BR /&gt;program:&lt;BR /&gt;*/calling date for the last saturday in sas date format;&lt;BR /&gt;&lt;BR /&gt;libname TEMP "/sasdata/Automation_AR/Raj_Bandi/TEMP";&lt;BR /&gt;libname DB META library="data-bric";&lt;BR /&gt;libname DB2 META library="data-brick2";&lt;BR /&gt;%let today = %sysfunc(today());&lt;BR /&gt;&lt;BR /&gt;%let lst_sat = %sysfunc(dhms(%sysfunc(intnx(day,&amp;amp;today,-6)),0,0,0));&lt;BR /&gt;%put &amp;amp;lst_sat;&lt;BR /&gt;&lt;BR /&gt;%let x= %sysfunc(putn(&amp;amp;lst_sat, datetime.));&lt;BR /&gt;%put &amp;amp;x;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;PROC SQL;&lt;BR /&gt;   CREATE TABLE TEMP.Cascade AS &lt;BR /&gt;   SELECT *&lt;BR /&gt;  FROM DB.V_COLN_RSRC_PD_CALL_FACT_H_TST t1&lt;BR /&gt;   where t1.CALENDAR_WK_ENDING_DATE = &amp;amp;x;&lt;BR /&gt;   Quit&lt;BR /&gt;&lt;BR /&gt;Log:&lt;BR /&gt;1                                                          The SAS System                         15:13 Thursday, September 23, 2021&lt;BR /&gt;&lt;BR /&gt;1          ;*';*";*/;quit;run;&lt;BR /&gt;2          OPTIONS PAGENO=MIN;&lt;BR /&gt;3          %LET _CLIENTTASKLABEL='Program 3';&lt;BR /&gt;4          %LET _CLIENTPROCESSFLOWNAME='Process Flow';&lt;BR /&gt;5          %LET&lt;BR /&gt;5        ! _CLIENTPROJECTPATH='C:\desktop\AppData\Roaming\SAS\EnterpriseGuide\8\AutoRecovery\d6f9ec4c-dd04-46d6-b4ad-1ae86eecbb&lt;BR /&gt;5        ! 1e\Project_(Recovered).egp';&lt;BR /&gt;6          %LET _CLIENTPROJECTPATHHOST='RBCONALF1TQZ6S';&lt;BR /&gt;7          %LET _CLIENTPROJECTNAME='Project_(Recovered).egp';&lt;BR /&gt;8          %LET _SASPROGRAMFILE='';&lt;BR /&gt;9          %LET _SASPROGRAMFILEHOST='';&lt;BR /&gt;10         &lt;BR /&gt;11         ODS _ALL_ CLOSE;&lt;BR /&gt;12         OPTIONS DEV=SVG;&lt;BR /&gt;13         GOPTIONS XPIXELS=0 YPIXELS=0;&lt;BR /&gt;14         %macro HTML5AccessibleGraphSupported;&lt;BR /&gt;15             %if %_SAS_VERCOMP_FV(9,4,4, 0,0,0) &amp;gt;= 0 %then ACCESSIBLE_GRAPH;&lt;BR /&gt;16         %mend;&lt;BR /&gt;17         FILENAME EGHTML TEMP;&lt;BR /&gt;18         ODS HTML5(ID=EGHTML) FILE=EGHTML&lt;BR /&gt;19             OPTIONS(BITMAP_MODE='INLINE')&lt;BR /&gt;20             %HTML5AccessibleGraphSupported&lt;BR /&gt;21             ENCODING='utf-8'&lt;BR /&gt;22             STYLE=HtmlBlue&lt;BR /&gt;23             NOGTITLE&lt;BR /&gt;24             NOGFOOTNOTE&lt;BR /&gt;25             GPATH=&amp;amp;sasworklocation&lt;BR /&gt;26         ;&lt;BR /&gt;NOTE: Writing HTML5(EGHTML) Body file: EGHTML&lt;BR /&gt;27         &lt;BR /&gt;28         */calling date for the last saturday in sas date format;&lt;BR /&gt;29         &lt;BR /&gt;30         libname TEMP "/sasdata/Automation_AR/Raj_Bandi/TEMP";&lt;BR /&gt;NOTE: Libref TEMP was successfully assigned as follows: &lt;BR /&gt;      Engine:        V9 &lt;BR /&gt;      Physical Name: /sasdata/Automation_AR/Raj_Bandi/TEMP&lt;BR /&gt;31         libname DB META library="data-brick";&lt;BR /&gt;NOTE: Libref DB was successfully assigned as follows: &lt;BR /&gt;      Engine:        META &lt;BR /&gt;      Physical Name: DB&lt;BR /&gt;32         libname DB2 META library="data-brick2";&lt;BR /&gt;NOTE: Libref DB2 was successfully assigned as follows: &lt;BR /&gt;      Engine:        META &lt;BR /&gt;      Physical Name: DB2&lt;BR /&gt;33         %let today = %sysfunc(today());&lt;BR /&gt;34         &lt;BR /&gt;35         %let lst_sat = %sysfunc(dhms(%sysfunc(intnx(day,&amp;amp;today,-6)),0,0,0));&lt;BR /&gt;36         %put &amp;amp;lst_sat;&lt;BR /&gt;1947542400&lt;BR /&gt;37         &lt;BR /&gt;38         %let x= %sysfunc(putn(&amp;amp;lst_sat, datetime.));&lt;BR /&gt;39         %put &amp;amp;x;&lt;BR /&gt;18SEP21:00:00:00&lt;BR /&gt;40         &lt;BR /&gt;41         &lt;BR /&gt;42         &lt;BR /&gt;43         PROC SQL;&lt;BR /&gt;44            CREATE TABLE TEMP.Cascade AS&lt;BR /&gt;2                                                          The SAS System                         15:13 Thursday, September 23, 2021&lt;BR /&gt;&lt;BR /&gt;45            SELECT *&lt;BR /&gt;46           FROM DB.V_COLN_RSRC_PD_CALL_FACT_H_TST t1&lt;BR /&gt;47            where t1.CALENDAR_WK_ENDING_DATE = &amp;amp;x;&lt;BR /&gt;NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;BR /&gt;NOTE: Line generated by the macro variable "X".&lt;BR /&gt;47          18SEP21:00:00:00&lt;BR /&gt;              _____&lt;BR /&gt;              22&lt;BR /&gt;              76&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: ;, !, !!, &amp;amp;, *, **, +, -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, AND, EQ, EQT, EXCEPT, &lt;BR /&gt;              GE, GET, GROUP, GT, GTT, HAVING, INTERSECT, LE, LET, LT, LTT, NE, NET, NOT, OR, ORDER, OUTER, UNION, ^, ^=, |, ||, ~, &lt;BR /&gt;              ~=.  &lt;BR /&gt;&lt;BR /&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;BR /&gt;&lt;BR /&gt;48            Quit&lt;BR /&gt;49         &lt;BR /&gt;50         %LET _CLIENTTASKLABEL=;&lt;BR /&gt;51         %LET _CLIENTPROCESSFLOWNAME=;&lt;BR /&gt;52         %LET _CLIENTPROJECTPATH=;&lt;BR /&gt;53         %LET _CLIENTPROJECTPATHHOST=;&lt;BR /&gt;54         %LET _CLIENTPROJECTNAME=;&lt;BR /&gt;55         %LET _SASPROGRAMFILE=;&lt;BR /&gt;56         %LET _SASPROGRAMFILEHOST=;&lt;BR /&gt;57         &lt;BR /&gt;58         ;&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;      real time           0.00 seconds&lt;BR /&gt;      cpu time            0.00 seconds&lt;BR /&gt;      &lt;BR /&gt;58       !  *';*";*/;quit;run;&lt;BR /&gt;59         ODS _ALL_ CLOSE;&lt;BR /&gt;60         &lt;BR /&gt;61         &lt;BR /&gt;62         QUIT; RUN;&lt;BR /&gt;63         &lt;BR /&gt;</description>
      <pubDate>Fri, 24 Sep 2021 19:11:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-Datetime-into-a-SAS-query-using-MACROS/m-p/770344#M244390</guid>
      <dc:creator>PrudhviB</dc:creator>
      <dc:date>2021-09-24T19:11:54Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Datetime into a SAS query using MACROS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-Datetime-into-a-SAS-query-using-MACROS/m-p/770345#M244391</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/279632"&gt;@PrudhviB&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi SAS Experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to pass datetime value into a sas query and its not working for me.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;here is my query and any help is appreciated.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;MACRO:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;%let today = %sysfunc(today());&lt;/P&gt;
&lt;P&gt;%let NEXT_DAY_1 = %sysfunc(dhms(%sysfunc(intnx(day,&amp;amp;today,-2)),0,0,0));&lt;BR /&gt;%put &amp;amp;NEXT_DAY_1;&lt;/P&gt;
&lt;P&gt;%let x= %sysfunc(putn(&amp;amp;NEXT_DAY_1, datetime.));&lt;BR /&gt;%put &amp;amp;x;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;O/P:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;22SEP21:00:00:00&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;SAS Query&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;this is where i am passing the macro date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;WHERE t1.CALENDAR_WK_ENDING_DATE = &amp;amp;x;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;ERROR:&lt;/STRONG&gt;&lt;/U&gt;&lt;BR /&gt;NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;BR /&gt;NOTE: Line generated by the macro variable "X".&lt;BR /&gt;80 18SEP21:00:00:00&lt;BR /&gt;_____&lt;BR /&gt;22&lt;BR /&gt;76&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: ;, !, !!, &amp;amp;, *, **, +, -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, AND, EQ, EQT, EXCEPT, &lt;BR /&gt;GE, GET, GROUP, GT, GTT, HAVING, INTERSECT, LE, LET, LT, LTT, NE, NET, NOT, OR, ORDER, OUTER, UNION, ^, ^=, |, ||, ~, &lt;BR /&gt;~=.&lt;/P&gt;
&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;it takes this format for some reason.&amp;nbsp;&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;'13Sep2021:0:0:0'dt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The code you use:&lt;/P&gt;
&lt;PRE&gt;WHERE t1.CALENDAR_WK_ENDING_DATE = &amp;amp;x;&lt;/PRE&gt;
&lt;P&gt;Would resolve to&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;WHERE t1.CALENDAR_WK_ENDING_DATE = 22SEP21:00:00:00;&lt;/PRE&gt;
&lt;P&gt;Which is not legal syntax and throws the error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is NO reason to use the formatted value.&lt;/P&gt;
&lt;P&gt;Use&lt;/P&gt;
&lt;PRE&gt;WHERE t1.CALENDAR_WK_ENDING_DATE = &amp;amp;NEXT_DAY_1;&lt;/PRE&gt;
&lt;P&gt;The value would resolve to the numeric datetime value and not throw any error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;'13Sep2021:0:0:0'dt;&lt;/PRE&gt;
&lt;P&gt;works because that is a datetime literal. And if you use similar code with the macro and examine that datetime literal the numeric values are the same: (running on 24Sep2021)&lt;/P&gt;
&lt;PRE&gt;461  %let today = %sysfunc(today());
462
463  %let NEXT_DAY_1 = %sysfunc(dhms(%sysfunc(intnx(day,&amp;amp;today,-2)),0,0,0));
464  %put Nex_date is: &amp;amp;NEXT_DAY_1;
Nex_date is: &lt;FONT size="5" color="#0000FF"&gt;&lt;STRONG&gt;1947888000&lt;/STRONG&gt;&lt;/FONT&gt;
465
466  data _null_;
467     x=intnx('dtday', '24Sep2021:0:0:0'dt,-2);
468     put x= ;
469  run;

x=&lt;FONT size="5" color="#FF00FF"&gt;&lt;STRONG&gt;1947888000
&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;An example of why formatting date, time or datetime values in macro variables in code for manipulations is not a good idea. Use the numeric value and keep the formatted values for text like titles and file names that people read.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Sep 2021 19:34:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-Datetime-into-a-SAS-query-using-MACROS/m-p/770345#M244391</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-09-24T19:34:46Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Datetime into a SAS query using MACROS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-Datetime-into-a-SAS-query-using-MACROS/m-p/770346#M244392</link>
      <description>&lt;P&gt;i just feel so dumb, how could i miss such a simple thing.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but thanks a ton you just saved a lot of time for me. Great work!&lt;/P&gt;</description>
      <pubDate>Fri, 24 Sep 2021 19:41:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-Datetime-into-a-SAS-query-using-MACROS/m-p/770346#M244392</guid>
      <dc:creator>PrudhviB</dc:creator>
      <dc:date>2021-09-24T19:41:32Z</dc:date>
    </item>
  </channel>
</rss>

