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.