Learning SAS? Welcome to the exclusive online community for all SAS learners.

Displaying date in YYYYMMDD format

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

Displaying date in YYYYMMDD format

How do I display date in the YYYYMMDD format? Like 1960/02/21.


Accepted Solutions
Solution
‎01-19-2017 04:35 PM
Super User
Posts: 5,513

Re: Displaying date in YYYYMMDD format

Posted in reply to opoudyal0

If you want to continue to use the same variable name, you need to output the result as character.  For example:

 

datevar = put ( input(datevar, mmddyy10.), yymmdds10. );

 

View solution in original post


All Replies
Super User
Posts: 7,831

Re: Displaying date in YYYYMMDD format

Posted in reply to opoudyal0

The yymmdd format is what you are looking for.

data test;
datevar = date();
format datevar yymmdd10.;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 5,513

Re: Displaying date in YYYYMMDD format

Posted in reply to opoudyal0

I can't test it right now, but you should be able to control the separator as well:

 

format datevar yymmdds10.;

format datevar yymmddd10.;

 

s = slash

d = dash

Super User
Posts: 7,831

Re: Displaying date in YYYYMMDD format

Posted in reply to Astounding

Astounding wrote:

I can't test it right now, but you should be able to control the separator as well:

 

format datevar yymmdds10.;

format datevar yymmddd10.;

 

s = slash

d = dash


The default separator for the YYMMDD format is the dash or hyphen.

Possible separators for the extended version of the format (as @Astounding posted) are

n no separator

b blank

d dash

s slash

p period

c colon

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 6

Re: Displaying date in YYYYMMDD format

Posted in reply to Astounding

What about if my date is a character variable and not numeric? For example: I have 11/5/1969 read in as character and I need to change it to the YYYYMMDD format.

Super User
Posts: 7,831

Re: Displaying date in YYYYMMDD format

Posted in reply to opoudyal0

Depending on the format, do

datvar = input(stringvar,ddmmyy10.);

or

datvar = input(stringvar,mmddyy10.);
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Solution
‎01-19-2017 04:35 PM
Super User
Posts: 5,513

Re: Displaying date in YYYYMMDD format

Posted in reply to opoudyal0

If you want to continue to use the same variable name, you need to output the result as character.  For example:

 

datevar = put ( input(datevar, mmddyy10.), yymmdds10. );

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 8617 views
  • 0 likes
  • 3 in conversation