Hello,
I have a table called POLAIM_MERGE that includes the field LOAD_LAST_DATETIME (format=datetime20, informat=datetime20)
data POLAIM_ADD_FORMAT;
set POLAIM_MERGE;
mydate =datepart(LOAD_LAST_DATETIME);
mytime = timepart(LOAD_LAST_DATETIME);
format mydate ddmmyy10. mytime time5.;
LOAD_LAST_DATETIME_NEW= put(mydate,ddmmyy10.)||' '||put(mytime,time5.);
run;
I wrote the following code but I get in the field "mytime" the time 9:03, I would like the leading 0 to be displayed at the time, desired display: 09:03 How do I change the code to show as I need?
Thanks.
The TODw. format will write a leading 0.
data POLAIM_ADD_FORMAT;
set POLAIM_MERGE;
mydate =datepart(LOAD_LAST_DATETIME);
mytime = timepart(LOAD_LAST_DATETIME);
format mydate ddmmyy10. mytime tod5.;
LOAD_LAST_DATETIME_NEW= put(mydate,ddmmyy10.)||' '||put(mytime,tod5.);
run;
Why are you bothering to create a character value for that value? It won't sort properly and can't be used an form of calculation.
You can create a custom format to display the existing value with a different appearance:
proc format; picture mydatetime low-high ='%0d/%0m/%Y %0H:%0M' (datatype=datetime); run; data example; x='07May2023:09:12:01'dt; format x mydatetime.; run;
This is one place that you really want to use single quotes to prevent confusion with the macro processor and the format directives. The CASE of the letters in the directives for the date and time portions are critical.
The / space and : are inserted in the relative positions.
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.