Hi guys,
I have this format date:
04Apr2023 9:51:00 and I want to convert into this format, keeping the time 04/04/2023 9:51:00
Do you known any format type I could use?
You show an hour with no leading 0. do you want minutes with no leading 0? How about Seconds if there is only one digit worth?
You picked a bad date as the example. I can't tell if you actually want a month/day/year order or day/month/year.
Do you want 00:00:00 for midnight or 24:00:00? Are times after noon 1:00:00 or 13:00:00 ?
Proc Format will let you roll pretty much any date, time or datetime format that you want but a clear description of what goes into each position is needed.
This will make format that displays the date in Month/day/year order with leading 0 for months or days of the month < 10, uses a 00:00:00 to 23:59:59 clock value and shows the leading 0 for hours, minutes and seconds when < 10.
proc format; picture mydt low-high='%0m/%0d/%Y %0H:%0M:%0S' (datatype=datetime) ; run;
All those %0lettter combinations are directives for displaying date and time elements. You do want to use single quotes here as double quotes will get the % interpreted by the macro processor and not in a good way.
You show an hour with no leading 0. do you want minutes with no leading 0? How about Seconds if there is only one digit worth?
You picked a bad date as the example. I can't tell if you actually want a month/day/year order or day/month/year.
Do you want 00:00:00 for midnight or 24:00:00? Are times after noon 1:00:00 or 13:00:00 ?
Proc Format will let you roll pretty much any date, time or datetime format that you want but a clear description of what goes into each position is needed.
This will make format that displays the date in Month/day/year order with leading 0 for months or days of the month < 10, uses a 00:00:00 to 23:59:59 clock value and shows the leading 0 for hours, minutes and seconds when < 10.
proc format; picture mydt low-high='%0m/%0d/%Y %0H:%0M:%0S' (datatype=datetime) ; run;
All those %0lettter combinations are directives for displaying date and time elements. You do want to use single quotes here as double quotes will get the % interpreted by the macro processor and not in a good way.
I'm doning a select from a table in a proc sql and I just want to convert 04Apr2023 09:51:00 into 04/04/2023 09:51:00 dd/mm/yyyy hh:mm:ss, if I use a datepart with a format ddmmyy10. I lose the time, and I don't want to lose the time.
No need to convert, just use a proper format.
@ballardw has already shown how to create one yourself.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.