BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Jose7
Obsidian | Level 7

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?

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

 

View solution in original post

7 REPLIES 7
ballardw
Super User

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.

 

Jose7
Obsidian | Level 7
Thks so much for your help, It works fine!
Jose7
Obsidian | Level 7

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.

Jose7
Obsidian | Level 7
Do you know where I can find de proper format?
Jose7
Obsidian | Level 7
I Had not understood, sorry, now I tried it and it works wonderful, thanks to clear the topic

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 606 views
  • 1 like
  • 3 in conversation