BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
dgoel
Fluorite | Level 6

 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. 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

@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.);

 

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

Try format YYMMDD10.

PaigeMiller
Diamond | Level 26

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

--
Paige Miller
Tom
Super User Tom
Super User

@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.);

 

dgoel
Fluorite | Level 6

Thank You, it worked.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 5795 views
  • 1 like
  • 4 in conversation