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.
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.
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.