I am looking for the global variable which has the format of YYYY-MM-DD
For example:
I have TD_ASOFDT which returns '2019-10-16'
I have date which is of format YYYYMMDDN8 and returns like 20191016.
How can I return 2019-10-16, i.e. there are - as separators but no inverted commas.
@dgoel wrote:
I am looking for the global variable which has the format of YYYY-MM-DD
For example:
I have TD_ASOFDT which returns '2019-10-16'
I have date which is of format YYYYMMDDN8 and returns like 20191016.
How can I return 2019-10-16, i.e. there are - as separators but no inverted commas.
What is a global variable? Did you mean a macro variable? Perhaps one defined in the GLOBAL scope?
Hopefully your macro variable does not include upside commas (what does that even mean? Are you talking about fancy quotes with different angles for opening and closing quotes?) but instead has nice normal single quote characters, like in your example.
To convert '2019-10-16' to 2019-10-16 just remove the quotes.
%let want=%sysfunc(dequote(&TD_ASOFDT ));
It is not at all clear what your other variable is or even what name to use to refer to it.
Is it also a macro variable? Or is it an actual variable in a dataset?
Let's assume, again, that you are talking about a character string stored in a macro variable. (Note that everything stored in a macro variable is a character string.)
You could convert it to a date and then regenerate a character string again only using a format that generates the characters you want.
%let want=%sysfunc(inputn(&date,yymmdd8.),yymmdd10.);
Try format YYMMDD10.
@dgoel wrote:
I have TD_ASOFDT which returns '2019-10-16'
I have date which is of format YYYYMMDDN8 and returns like 20191016.
How can I return 2019-10-16, i.e. there are - as separators but no inverted commas.
If your format is 8 characters wide, you don't have enough room left to right to include the dashes/hyphens.
Try format YYMMDDD10.
@dgoel wrote:
I am looking for the global variable which has the format of YYYY-MM-DD
For example:
I have TD_ASOFDT which returns '2019-10-16'
I have date which is of format YYYYMMDDN8 and returns like 20191016.
How can I return 2019-10-16, i.e. there are - as separators but no inverted commas.
What is a global variable? Did you mean a macro variable? Perhaps one defined in the GLOBAL scope?
Hopefully your macro variable does not include upside commas (what does that even mean? Are you talking about fancy quotes with different angles for opening and closing quotes?) but instead has nice normal single quote characters, like in your example.
To convert '2019-10-16' to 2019-10-16 just remove the quotes.
%let want=%sysfunc(dequote(&TD_ASOFDT ));
It is not at all clear what your other variable is or even what name to use to refer to it.
Is it also a macro variable? Or is it an actual variable in a dataset?
Let's assume, again, that you are talking about a character string stored in a macro variable. (Note that everything stored in a macro variable is a character string.)
You could convert it to a date and then regenerate a character string again only using a format that generates the characters you want.
%let want=%sysfunc(inputn(&date,yymmdd8.),yymmdd10.);
Thank You, it worked.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: