Hi there
I am a new SAS user.
I have a character DATETIME variable named "run_date" recorded as "YYYY-MM-DD HH:MM" which has a 17 character length. (2018-OCT-11 09:15).
I want to convert into numeric datetime variable in date19 format.
Hope you can help.
Thanks
Yuba
There is not such thing as a DATE19. format DATE formats run from 5 to 11.
You would want a DATETIME format to display the time component.
Congratulations for finding one of the sillier date time formats:
data example; x="2018-OCT-11 09:15"; y = dhms(input(x,anydtdte11.),0,0,input(substr(x,13),time.)); format y datetime19.; run;
Which uses a specific length to read the date part from the first 11 characters and the time from the last 5.
If your "dates" don't have 2-digit values for the day this will likely fail.
Hi Reeza
Thanks a lot for your quick response.
The program you suggested runs perfectly with no error message on the log window. but the output data has all the 'run_date_num' as blank.
The original variable was in Character format $17 and informat$17 and not all observations have a 'run date' data.
This is surprising, any idea what could be the reason.
Thanks
Yuba
Show your code and log please. Could be anything from a missing semicolon to a different format for you date than shown in your question.
@yubaraj wrote:
Hi Reeza
Thanks a lot for your quick response.
The program you suggested runs perfectly with no error message on the log window. but the output data has all the 'run_date_num' as blank.
The original variable was in Character format $17 and informat$17 and not all observations have a 'run date' data.
This is surprising, any idea what could be the reason.
Thanks
Yuba
NVM - its because you have a very unique data format and you'll need a specific informat for it.
"YYYY-MM-DD HH:MM" => this is a standard format and my methods works in this case
2018-OCT-11 09:15 => this is a non-standard format and my method does not work in this case.
My apologies, I didn't notice the discrepancy between these initially. See below.
data example;
date_have = "2018-OCT-11 09:15";
date_want = input(date_have, anydtdtm.);
output;
date_have = "2018-10-11 09:15";
date_want = input(date_have, anydtdtm.);
output;
format date_want datetime.;
run;
proc print data=example;
run;
There is not such thing as a DATE19. format DATE formats run from 5 to 11.
You would want a DATETIME format to display the time component.
Congratulations for finding one of the sillier date time formats:
data example; x="2018-OCT-11 09:15"; y = dhms(input(x,anydtdte11.),0,0,input(substr(x,13),time.)); format y datetime19.; run;
Which uses a specific length to read the date part from the first 11 characters and the time from the last 5.
If your "dates" don't have 2-digit values for the day this will likely fail.
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.
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.