Hello,
I do need to change date in YYYY-MM-DD format by using the macro value.
%LET start_date = '01Feb2022'd;
%let start = (&start_date., yymmdd10.);
%put &start.;
start should be 2022-02-01.
The macro processor needs additional instruction in order to work with dates. This is the %SYSEVALF function and the %SYSFUNC function.
Please note for clarity, now and in the future: your title implies you are working with macros. You are not working with macros. You are working with macro variables, which is something different than a macro. Do not use "macro" to refer to "macro variables".
%let start_date = %sysevalf('01feb2022'd);
%let start = %sysfunc(putn(&start_date, yymmdd10.));
%put &=start;
No need to add the %SYSEVALF() if you are going to use the value with %SYSFUNC(). Unlike the %EVAL() macro function used for most macro code evaluations the SAS data step functions know how to interpret literals directly.
238 %let start_date = '01Feb2022'd; 239 %let start = %sysfunc(putn(&start_date., yymmdd10.)); 240 %put &=start_date &=start; START_DATE='01Feb2022'd START=2022-02-01
Starting day of month for current month in desired format
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; SYMBOLGEN: Macro variable _SASWSTEMP_ resolves to /home/fkhurshed/.sasstudio/.images/9a0e017f-022a-4352-9956-2f959c2997c7 SYMBOLGEN: Some characters in the above value which were subject to macro quoting have been unquoted for printing. SYMBOLGEN: Macro variable GRAPHINIT resolves to GOPTIONS RESET=ALL GSFNAME=_GSFNAME; 68 69 %let start = %sysfunc(intnx(month, %sysfunc(today()), 0, b), yymmdd10.); 70 %put &start.; SYMBOLGEN: Macro variable START resolves to 2022-02-01 2022-02-01
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.