I am using SAS Enterprise Guide and I am trying to format a text field by the name of 'Admit Date' with data such as: 20180110164700 to a datetime format. Hopefully formatted to YYYY-MM-DD HH:MM:SS. Any help would be appreciated.
Thank you
Well, in code you do (and this assumes I am right on what the date should be - really a good idea to get the sender to apply some sort of standard date format to the data, something like ISO dates):
data want; set have; mydt=dhms(input(substr(text,1,8),yymmdd8.),input(substr(text,9,2),best.),input(substr(text,10,2),best.),input(substr(text,12,2),best.)); format mydt datetime.; run;
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.