Hello,
Please, I have date and time in character form and I need help converting it to SAS datetime format.
I am looking for this format
Thank you.
You can do that in one step, and it needs small corrections.
Data _data7f;
Set _data7e;
abx_date=input(scan(abx_datetime,1,' '),mmddyy10.); /* 1 instead of -1 */
abx_time=input(scan(abx_datetime,2,' '),time8.); /* 2 instead if -1 */
abx_datetime_num = dhms(abx_date,0,0,abx_time);
format
abx_date mmddyy10.
abx_time time8.
abx_datetime_new e8601dt19.
;
run;
Thank you for the update
Please, I used the following codes that was marked as the solution to a similar question asked in the past and marked as the solution but it does not seem to work for me. I guess I may be doing something wrong. I sincerely appreciate your assistance.
Data data7f;
Set data7e;
abx_datetime2=DHMS(Input(Scan(abx_datetime,1,' '),MMDDYY10.),Scan(Scan(abx_datetime,2,' '),1,':'),Scan(Scan(abx_datetime,2,' '),2,':'),Scan(Scan(abx_datetime,2,' '),3,':'));
Format abx_datetime2 DateTime19.;
Run;
Thank you in advance
Convert date and time separately. Use SCAN() to extract the first and second "word", use INPUT() to convert (the date with MMDDYY10., the time with TIME8.), and then the DHMS() function to combine everything into the new variable, to which you assign the DATETIME19. format. Use the time as the "seconds" parameter of DHMS().
Thank you for your response.Please, I am not sure I understand clearly how to use the scan statement but I used the following codes for extract data and time but it is not working. I would sincerely appreciate some help writing the code. Thank you in advance.
Data _data7f;
Set _data7e;
abx_date=input(scan(abx_datetime,-1,' '),mmddyy10.);
format abx_date mmddyy10.;
run;
Data _data7f;
Set _data7f;
abx_time=input(scan(abx_datetime,-1,' '),time8.);
format abx_date time8.;
run;
You can do that in one step, and it needs small corrections.
Data _data7f;
Set _data7e;
abx_date=input(scan(abx_datetime,1,' '),mmddyy10.); /* 1 instead of -1 */
abx_time=input(scan(abx_datetime,2,' '),time8.); /* 2 instead if -1 */
abx_datetime_num = dhms(abx_date,0,0,abx_time);
format
abx_date mmddyy10.
abx_time time8.
abx_datetime_new e8601dt19.
;
run;
Thank you so much Kurt for the assistance. I am grateful.
I changed the format for the datetime from e8601dt19. to Datetime19. and it worked just fine.
Thank you again.
If the advice that @Kurt_Bremser has given you takes care of everything, well and good.
However, if things are still not working, would you please run the following code and post the results here? I'm interested in the results not the log.
Jim
Proc Contents Data=_data7e;
RUN;
I just tried some code, see below, and I was able to read the data using an INformat (anydtdtm16.) and then format the value using Format datetime17. If this is already solved, then do not worry about it, but if not, perhaps it's worth experimenting with the below code. My results are below the code.
Jim
DATA _data7e;
FORMAT Date_Value DATETIME17.;
INPUT Date_Value & : ANYDTDTM16.;
DATALINES;
11/8/2016 22:49
11/14/2016 10:00
11/14/2016 10:04
2/5/2017 16:01
2/5/2017 18:34
;
RUN;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.