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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 1106 views
  • 2 likes
  • 3 in conversation