BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Q1983
Lapis Lazuli | Level 10
%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

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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)

--
Paige Miller

View solution in original post

4 REPLIES 4
Reeza
Super User
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


 

PaigeMiller
Diamond | Level 26

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)

--
Paige Miller
ballardw
Super User

@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?

data_null__
Jade | Level 19

@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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1079 views
  • 2 likes
  • 5 in conversation