BookmarkSubscribeRSS Feed
mlogan
Lapis Lazuli | Level 10

Hi there,

I have a column which is showing as character (yyyy-mm-dd) and I want to change that to mm/dd//yyyy date format, can someone please help.

 

Thanks,

 

Mike

3 REPLIES 3
jimbarbour
Meteorite | Level 14

Here's a code sample (tested) bringing the text data in yyyy-mm-dd format and putting it out in MMDDYYS10. format.  Results below.

 

You can either create a formatted text variable (New) or a SAS date variable with a format (New2).

 

Jim

 

jimbarbour_0-1602622537989.png

 

DATA	DATE_DATA2;
	Old		=	'2020-10-13';
	New		=	PUT(INPUT(OLD, ANYDTDTE10.), MMDDYYS10.);
	New2	=	INPUT(OLD, ANYDTDTE10.);
	FORMAT	New2	MMDDYYS10.;
RUN;

 

Reeza
Super User

Do you want a SAS date or a character variable for the new variable?

 

I generally recommend a SAS date as it offers more flexibility.

 

data demo;

char_date = "2020-01-01";

SAS_date1 = input(char_date, yymmdd10.);
format sas_date1 yymmdd10.;

SAS_date2 = sas_date1;
format sas_date2 mmddyyd10.;

sas_date3 = sas_date1;
format sas_date3 date9.;

date_char_new = put(sas_date1, mmddyyd10.);

run;

proc print data=demo;run;

@mlogan wrote:

Hi there,

I have a column which is showing as character (yyyy-mm-dd) and I want to change that to mm/dd//yyyy date format, can someone please help.

 

Thanks,

 

Mike


 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 6616 views
  • 2 likes
  • 4 in conversation