SAS Software for Learning Community

Welcome to the exclusive online community for all SAS learners.
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
opoudyal0
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

6 REPLIES 6
Astounding
PROC Star

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

Kurt_Bremser
Super User

@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

opoudyal0
Calcite | Level 5

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.

Astounding
PROC Star

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

 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 6 replies
  • 153715 views
  • 5 likes
  • 3 in conversation