BookmarkSubscribeRSS Feed
Smitha9
Fluorite | Level 6

Hi,

I have a data,

2020-03-20 13:00:23

2019-04-28 14:18:00

2015-05-20 15:20:30

I want to change to 

03/20/2020 13:00:23

04/28/2019 14:18:00

05/20/2015 15:20:30

 

can you let me know the code.

thank you.

4 REPLIES 4
Jagadishkatam
Amethyst | Level 16
Is the date in character format
Thanks,
Jag
Jagadishkatam
Amethyst | Level 16

If the date is in character format then you may try the below code

 

data have;
input date&$20.;
cards;
2020-03-20 13:00:23
2019-04-28 14:18:00
2015-05-20 15:20:30
;

data want;
set have;
date2=cat(put(input(scan(date,1,''),yymmdd10.),ddmmyys10.),scan(date,2,''));
run;
Thanks,
Jag
Kurt_Bremser
Super User

To convert from character, use the E8601DT informat:

data have;
input datechar $19.;
datenum = input(datechar,e8601dt19.);
format datenum nldatms19.;
datalines;
2020-03-20 13:00:23
2019-04-28 14:18:00
2015-05-20 15:20:30
;

How the datetime is displayed depends on the setting of the LOCALE= system option.

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 837 views
  • 2 likes
  • 3 in conversation