%let mydate = %sysfunc(putn(%sysfunc(intnx(day, %sysfunc(today()), -1, end)), yymmddd8.)); %put &mydate;/*SYMBOLGEN: Macro variable MYDATE resolves to 21-06-09*/
However I want this output 2020-06-09 or what ever the date is
I tried yyymmdd10 with no result
Format should be yymmddd10.
The old triple-Sysfunc! Much easier to do this in a data step, and then you don't have to type as much, and you have fewer chances to misplace a parenthesis.
data _null_;
call symputx('mydate',put(today()-1,yymmddd10.));
run;
%put &=mydate;
Another advice: most of the time, macro variables SHOULD NOT be formatted. If you do format your macro variable, as you have done, this just makes future coding with the macro variable more complex. So you should usually leave macro variables unformatted. See Maxim 28. (There are exceptions, like if you want to use the macro variable in a title or label or sometimes when an external database requires dates as character strings)
69 %let mydate = %sysfunc(putn(%sysfunc(intnx(day, %sysfunc(today()), -1, end)), yymmddd10.)); 70 %put &mydate;/*SYMBOLGEN: Macro variable MYDATE resolves to 21-06-09*/ 2021-06-09
Works fine for me.
@Q1983 wrote:
%let mydate = %sysfunc(putn(%sysfunc(intnx(day, %sysfunc(today()), -1, end)), yymmddd8.)); %put &mydate;/*SYMBOLGEN: Macro variable MYDATE resolves to 21-06-09*/However I want this output 2020-06-09 or what ever the date is
I tried yyymmdd10 with no result
Format should be yymmddd10.
The old triple-Sysfunc! Much easier to do this in a data step, and then you don't have to type as much, and you have fewer chances to misplace a parenthesis.
data _null_;
call symputx('mydate',put(today()-1,yymmddd10.));
run;
%put &=mydate;
Another advice: most of the time, macro variables SHOULD NOT be formatted. If you do format your macro variable, as you have done, this just makes future coding with the macro variable more complex. So you should usually leave macro variables unformatted. See Maxim 28. (There are exceptions, like if you want to use the macro variable in a title or label or sometimes when an external database requires dates as character strings)
@Q1983 wrote:
%let mydate = %sysfunc(putn(%sysfunc(intnx(day, %sysfunc(today()), -1, end)), yymmddd8.)); %put &mydate;/*SYMBOLGEN: Macro variable MYDATE resolves to 21-06-09*/However I want this output 2020-06-09 or what ever the date is
I tried yyymmdd10 with no result
Devils advocate: if you want 10 characters (count them in 2020-06-09) why did you use a format that only displays 8: yymmddd8. ? When you add the dashes that leaves 6 characters for the actual date.
I don't know what your Symbolgen says but that displays as 21-06-09 when I run the code on 09JUN2021.
Are you sure you have the right system clock setting for date?
@Q1983 wrote:
%let mydate = %sysfunc(putn(%sysfunc(intnx(day, %sysfunc(today()), -1, end)), yymmddd8.)); %put &mydate;/*SYMBOLGEN: Macro variable MYDATE resolves to 21-06-09*/However I want this output 2020-06-09 or what ever the date is
I tried yyymmdd10 with no result
You should use the SYSFUNC format parameter. No need for %SYSFUNC(PUTN
55 %let mydate = %sysfunc(intnx(day,%sysfunc(today()),-1,end),yymmddd10);
56 %put &mydate Using SYSFUNC format parameter;
2021-06-09 Using SYSFUNC format parameter
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.