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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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