MMDDYY10 FORMAT TO DATETIME20

Accepted Solution Solved
Reply
Contributor
Posts: 33
Accepted Solution

MMDDYY10 FORMAT TO DATETIME20

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;


Accepted Solutions
Solution
‎12-18-2015 10:56 AM
Super User
Posts: 10,548

Re: MMDDYY10 FORMAT TO DATETIME20

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


All Replies
Solution
‎12-18-2015 10:56 AM
Super User
Posts: 10,548

Re: MMDDYY10 FORMAT TO DATETIME20

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.

Contributor
Posts: 33

Re: MMDDYY10 FORMAT TO DATETIME20

That worked, thanks so much!
🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 452 views
  • 0 likes
  • 2 in conversation