BookmarkSubscribeRSS Feed
PravinMishra
Quartz | Level 8

Hi

I have a date value

19370

19375

i would Like to convert it in

12JAN13:00:00:00

17JAN13:00:00:00

I am using below piece of code but it's not working

tranwrd(put(dhms(datepart(ldate),0,0,0),E8601DT19.),"T","");

Thanks

3 REPLIES 3
Reeza
Super User

Your values are dates so you don't need the date part function. The format you want is a SAS format, datetime21 so you can apply that directly. The code below demonstrates this, time_want is the numeric version of the variable and time_want_char is the character version of the variable.

data have;

input time;

cards;

19370

19375

;

run;

data want;

set have;

time2=time;

time_want=dhms(time, 0, 0, 0);

time_want_char=put(time_want, datetime21.);

format time time_want datetime21. time2 date9.;

run;

art297
Opal | Level 21

How about:?

data want;

  set have;

  ndt=tranwrd(put(dhms(ldate,0,0,0),E8601DT19.),"T","");

run;

stat_sas
Ammonite | Level 13

data have;

input time;

time_want=time*86400;

format time_want datetime.;

cards;

19370

19375

;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 5653 views
  • 0 likes
  • 4 in conversation