<?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: Macro variable with date9. format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-date9-format/m-p/866698#M342291</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You wrote &lt;EM&gt;I do not understand why you think it is so important to keep the MPRINT output and the actual macro variable values unreadable.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We normally run production jobs with NOMPRINT, and MPRINT is only activated for debugging. That's why I like to put macro variable values in a human-readable form, so they appear in the log anyway and can be used in a first-level-debugging without having to read thousands of MPRINT lines.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And I really see date constants in macro variables as a nuisance. A SAS Date value will always work, but a date constant in a macro variable might give all kinds of trouble. It cannot be used in a macro calculation, and the presence of quotes in the value can also be troubleome, e.g. when building strings for CALL Execute using CAT-functions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider this example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;161    %let date_start = "%sysfunc(intnx(month,%sysfunc(today()),-3,b),date9.)"d;
162    %let date_start = %eval(&amp;amp;date_start + 7);
&lt;FONT color="#FF0000"&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
       operand is required. The condition was: "01DEC2022"d + 7&lt;/FONT&gt;
163    %put &amp;amp;=date_start;
DATE_START=&lt;BR /&gt;
164
165    %let date_start = %sysfunc(intnx(month,%sysfunc(today()),-3,b));
166    %let date_start = %eval(&amp;amp;date_start + 7);
167    %put %sysfunc(putn(&amp;amp;date_start,date9.));
08DEC2022

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best greetings&lt;/P&gt;
&lt;P&gt;Erik&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 28 Mar 2023 09:33:58 GMT</pubDate>
    <dc:creator>ErikLund_Jensen</dc:creator>
    <dc:date>2023-03-28T09:33:58Z</dc:date>
    <item>
      <title>Macro variable with date9. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-date9-format/m-p/866291#M342102</link>
      <description>&lt;P&gt;Following program yields the value of macro variable like 25MAR2023 which is similar to date9. format but without the single quotes and 'd'. But I need the value like '25MAR2023'd. Shed somelight on this issue to fix it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data _null_;
start_date_edh = put(intnx("month",today(),-3,"b"), date9.);
end_date_edh = put(today()-1, date9.);
call symput('start_date_edh', start_date_edh);
call symput('end_date_edh', end_date_edh);
run;   
&lt;/PRE&gt;</description>
      <pubDate>Sat, 25 Mar 2023 19:17:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-date9-format/m-p/866291#M342102</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2023-03-25T19:17:03Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable with date9. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-date9-format/m-p/866294#M342103</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Following program yields the value of macro variable like 25MAR2023 which is similar to date9. format but without the single quotes and 'd'. But I need the value like '25MAR2023'd. Shed somelight on this issue to fix it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data _null_;
start_date_edh = put(intnx("month",today(),-3,"b"), date9.);
end_date_edh = put(today()-1, date9.);
call symput('start_date_edh', start_date_edh);
call symput('end_date_edh', end_date_edh);
run;   
&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In most cases, you DO NOT need values with quotes around it. In most cases, you DO NOT want to format macro variables. See &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Maxim 28.&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
start_date_edh = put(intnx("month",today(),-3,"b"));
end_date_edh = put(today()-1);
call symput('start_date_edh', start_date_edh);
call symput('end_date_edh', end_date_edh);
run;   &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;gives you macro variables that you can use for any logical or arithmetic purpose. In most cases, an unformatted macro variable will work. If your variable is a true SAS date value (regardless of how it is formatted) this will work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    if date&amp;gt;&amp;amp;start_date_edh then do ... ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Mar 2023 20:37:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-date9-format/m-p/866294#M342103</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-03-25T20:37:28Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable with date9. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-date9-format/m-p/866298#M342106</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;But I need the value like '25MAR2023'd.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No you don't. Use the unformatted, raw date value and you can use the macro variable without further ado anywhere the value is needed.&lt;/P&gt;
&lt;P&gt;Formatted macro variables are only needed when you use them in a place where humans will read them (TITLEs, FOOTNOTEs and the like).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
call symputx('start_date_edh',intnx("month",today(),-3,"b"));
call symputx('end_date_edh',today() - 1);
run;   &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 25 Mar 2023 20:58:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-date9-format/m-p/866298#M342106</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-03-25T20:58:52Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable with date9. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-date9-format/m-p/866299#M342107</link>
      <description>&lt;P&gt;You can just add them when you need them at the point where you USE the macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;TITLE "Date between &amp;amp;start_date_edh and &amp;amp;end_date_edh";
proc print data=have;
  where date between "&amp;amp;start_date_edh"d and "&amp;amp;end_date_edh"d;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But if you never need to use the macro variable to print text that humans will read you can just skip formatting the dates.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  call symputx('start_date_edh', intnx("month",today(),-3,"b"));
  call symputx('end_date_edh', today()-1);
run;   
proc print data=have;
  where date between &amp;amp;start_date_edh and &amp;amp;end_date_edh;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;PS&lt;/STRONG&gt; Unless you need to include leading or trailing spaces in the macro variable values you should never use the ancient CALL SYMPUT() function.&amp;nbsp; Use the more modern CALL SYMPUTX(), it has more flexibility.&lt;/P&gt;</description>
      <pubDate>Sat, 25 Mar 2023 21:03:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-date9-format/m-p/866299#M342107</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-25T21:03:20Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable with date9. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-date9-format/m-p/866488#M342202</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;In most cases, you DO NOT need values with quotes around it. In most cases, you DO NOT want to format macro variables. See&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Maxim 28.&lt;/A&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I strongly disagree. If you are trying to find out what happens in a SAS program with code like&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where date between 12341 and 12418;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you will probably waste quite a long time trying to find out, compared to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where date between "01JAN2017"d and "31DEC2017"d&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which what your MPRINT output will look like with formatted values.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Already when you create the values, you will probably want to see the macro dates as text and not numbers. Just looking at values like 30DEC2022 makes it a lot easier to see if you actually did your date calculation correctly (yes, I think even YOU may sometimes make an error when writing formulas for calculating dates, and I know for certain that I do once in a while).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2023 09:32:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-date9-format/m-p/866488#M342202</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2023-03-27T09:32:45Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable with date9. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-date9-format/m-p/866490#M342204</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;In most cases, you DO NOT need values with quotes around it. In most cases, you DO NOT want to format macro variables. See&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Maxim 28.&lt;/A&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I strongly disagree. If you are trying to find out what happens in a SAS program with code like&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where date between 12341 and 12418;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you will probably waste quite a long time trying to find out&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The goal isn't getting the log that works best, the goal is getting code that works best. By using un-formatted macro variables, you reduce the probability of errors, since you don't have the format the macro variable and you don't have to "un-format" the macro variable by adding quotes and a d on the end. Fewer opportunities for mistakes, fewer opportunities for typographical errors, less typing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And why would it take a long time to figure out what 12341 represents? You know its a date value, it would take much less than a minute to figure this out.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2023 09:46:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-date9-format/m-p/866490#M342204</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-03-27T09:46:00Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable with date9. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-date9-format/m-p/866582#M342225</link>
      <description>&lt;P&gt;On top of what Paige already said, only WHERE statements, clauses or dataset options will display such values on their own. If the macro variable is used in calculations, conditions or as argument to a function, there is no automatic display of the value, so a PUT must be used anyway for control, where a format is easily added.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my professional SAS life, macro variables were either created through data steps, where a PUT is easily added, or imported from the scheduler via %SYSGET, and the INCLUDE which did this for all programs wrote all imported values to the log on its own.&lt;/P&gt;
&lt;P&gt;Writing a quick data _null_ to display a value was never much of an issue, compared to the much easier use of unformatted variables, which usually happened multiple times within a program.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2023 17:30:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-date9-format/m-p/866582#M342225</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-03-27T17:30:42Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable with date9. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-date9-format/m-p/866589#M342231</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In SAS, dates should never be kept in a data set as text values, but always converted to SAS Date values. Similar with macro variables, they should also contain SAS Date values unless they are created for the sole purpose of being human-readable, e.g. as part of a title statement. This way the macro variables can always be used in where-statements, data step functions etc. without any conversion, so the coding becomes simpler and less error-prone.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But it is also true that it is nice to have the date values written to the log in a readable form, as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt;&amp;nbsp; advocates. It is always a good practice to write a macro variable to the log when it has been assigned a value, and with a little effort, one can have both:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date_start = %sysfunc(intnx(month,%sysfunc(today()),-3,b));
%put &amp;amp;=date_start (%sysfunc(putn(&amp;amp;date_start,date9.)));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;DATE_START=22980 (01DEC2022)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2023 17:54:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-date9-format/m-p/866589#M342231</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2023-03-27T17:54:10Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable with date9. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-date9-format/m-p/866689#M342284</link>
      <description>&lt;P&gt;Or you could simply write&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date_start = "%sysfunc(intnx(month,%sysfunc(today()),-3,b),date9.)"d;
%put &amp;amp;=date_start;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And you will get&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATE_START="01DEC2022"d&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which is a SAS date constant. I do not understand why you think it is so important to keep the MPRINT output and the actual macro variable values unreadable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 08:06:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-date9-format/m-p/866689#M342284</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2023-03-28T08:06:44Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable with date9. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-date9-format/m-p/866698#M342291</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You wrote &lt;EM&gt;I do not understand why you think it is so important to keep the MPRINT output and the actual macro variable values unreadable.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We normally run production jobs with NOMPRINT, and MPRINT is only activated for debugging. That's why I like to put macro variable values in a human-readable form, so they appear in the log anyway and can be used in a first-level-debugging without having to read thousands of MPRINT lines.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And I really see date constants in macro variables as a nuisance. A SAS Date value will always work, but a date constant in a macro variable might give all kinds of trouble. It cannot be used in a macro calculation, and the presence of quotes in the value can also be troubleome, e.g. when building strings for CALL Execute using CAT-functions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider this example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;161    %let date_start = "%sysfunc(intnx(month,%sysfunc(today()),-3,b),date9.)"d;
162    %let date_start = %eval(&amp;amp;date_start + 7);
&lt;FONT color="#FF0000"&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
       operand is required. The condition was: "01DEC2022"d + 7&lt;/FONT&gt;
163    %put &amp;amp;=date_start;
DATE_START=&lt;BR /&gt;
164
165    %let date_start = %sysfunc(intnx(month,%sysfunc(today()),-3,b));
166    %let date_start = %eval(&amp;amp;date_start + 7);
167    %put %sysfunc(putn(&amp;amp;date_start,date9.));
08DEC2022

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best greetings&lt;/P&gt;
&lt;P&gt;Erik&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 09:33:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-date9-format/m-p/866698#M342291</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2023-03-28T09:33:58Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable with date9. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-date9-format/m-p/866700#M342292</link>
      <description>&lt;P&gt;OK, I beg to differ. The calculation&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%eval(&amp;amp;date_start + 7);&lt;/PRE&gt;
&lt;P&gt;can easily be done using %sysfunc(intnx()):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date2="%sysfunc(intnx(day,&amp;amp;date1,7),date9.)"d;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and as for CALL EXECUTE, the answer is: I don't. When I need to have a data step generate code, I&amp;nbsp; write the code to a temporary SAS file, which I then %INCLUDE. So that I can see the generated code before submitting, and I have all the wonderful flexibility and power of the PUT statement available when generating the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But actually, the CATx functions work with date constants as well as with numbers, e.g.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
1    data _null_;
2      a=cats('date in(',12345,',',"01DEC2004"d,')');
3      put a=;
4    run;

a=date in(12345,16406)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you need to do something funny with macro variables containing quotes in a data step, just SYMGET them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think readable dates and datetimes make programs a lot easier to debug and modify, and most of the time spent on a program is generally spent on maintenance, not on the initial coding.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 10:27:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-date9-format/m-p/866700#M342292</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2023-03-28T10:27:22Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable with date9. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-date9-format/m-p/866720#M342301</link>
      <description>&lt;P&gt;Just to join in, I'm also a fan of using date literals as values for macro variables, and a fan of always leaving MPRINT turned on.&amp;nbsp; (Nothing worse than seeing a log with an error in it but not seeing the code).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's unfortunate that %EVAL() doesn't know about date literals, but of course it has other limitations as well.&amp;nbsp; Happily %SYSEVALF knows about date literals:&lt;/P&gt;
&lt;PRE&gt;1    %let date_start = "%sysfunc(intnx(month,%sysfunc(today()),-3,b),date9.)"d;
2    %let date_start = %sysevalf(&amp;amp;date_start + 7);
3    %put %sysfunc(putn(&amp;amp;date_start,date9.));
08DEC2022
&lt;/PRE&gt;
&lt;P&gt;If I'm writing a macro that accepts a parameter that is a date, I think best practice is to accept either a SAS date or a date literal.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I agree with the general guidance that value of date macro variable should not be "formatted", so I wouldn't use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let mydate=03/28/2023;
%let mydate=28Mar2028;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I see a date literal as different than a formatted date string.&amp;nbsp; Because a date literal has a known numeric value.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 13:03:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-date9-format/m-p/866720#M342301</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-03-28T13:03:23Z</dc:date>
    </item>
  </channel>
</rss>

