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;
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.
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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.