BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BU2B
Calcite | Level 5

Hey all,

 

I need to convert a date format from MMDDYY10. to DATETIME20.  I've tried just about every suggestion I could Google and here and nothing is working.  Here's my latest stab...

 

DATA ETRM_CREP_VA1_SWING;

SET ETRM_CREP_VA1_SWING;

OPERATION_DT = INPUT(OPERATION_DT, MMDDYY10.)*86400;

RUN;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

You'll need a bit  more the new value should be built with the DHMS function to get the correct offset. If your current variable operation_dt is character then :

 

DATETIMEVariable = DHMS(input(operation_dt,mmddyy10.),0,0,0);

where the 0 are the hour, minute and second you want to assign, you could use any valid hour, minute and second value

If the Operation_DT variable is a SAS date value then you could use

Operation_DT = DHMS(Operation_DT ,0,0,0);

then assign a datetime format:

Format Operation_DT datetime20.;

I would strongly suggest not creating character variables to hold datetime values as if you ever need pieces, such as month, day, year, or want to compare with other values you end up with lots of headaches.

View solution in original post

2 REPLIES 2
ballardw
Super User

You'll need a bit  more the new value should be built with the DHMS function to get the correct offset. If your current variable operation_dt is character then :

 

DATETIMEVariable = DHMS(input(operation_dt,mmddyy10.),0,0,0);

where the 0 are the hour, minute and second you want to assign, you could use any valid hour, minute and second value

If the Operation_DT variable is a SAS date value then you could use

Operation_DT = DHMS(Operation_DT ,0,0,0);

then assign a datetime format:

Format Operation_DT datetime20.;

I would strongly suggest not creating character variables to hold datetime values as if you ever need pieces, such as month, day, year, or want to compare with other values you end up with lots of headaches.

BU2B
Calcite | Level 5
That worked, thanks so much!

sas-innovate-wordmark-2025-midnight.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!

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
  • 2 replies
  • 3545 views
  • 0 likes
  • 2 in conversation