Greetings
I have a table as attached
I have used the following code to update the field processed_on with today's date as a datetime
proc sql;
Update table1Set PROCESSED_ON = datetime();
alter table table1 modify PROCESSED_ON integer
format = datetime16.;quit;
The format on the resultant table is of the form 22Feb2022 14:34:16
How do I format the date field to start with the year like 2022-02-22 14:34:16
Thanks
Use (almost 1-to-1) example from the doc:
proc format;
picture myDateTime (default=19)
other = '%Y-%0m-%0d %0H:%0M:%0S' (datatype=datetime);
;
run;
data _null_;
x = '22Feb2022 14:34:16'dt;
put x myDateTime.;
run;
Bart
SAS provides a family of formats compliant with the ISO 8601 standard for dates and times.
If the E8601DT19. format does not suit you because of the "T", roll your own picture format with PROC FORMAT.
Use (almost 1-to-1) example from the doc:
proc format;
picture myDateTime (default=19)
other = '%Y-%0m-%0d %0H:%0M:%0S' (datatype=datetime);
;
run;
data _null_;
x = '22Feb2022 14:34:16'dt;
put x myDateTime.;
run;
Bart
The solution worked well
You do want to be very careful in SAS thinking "date" when the value is actually a "datetime". The units are not the same and when you apply "date" functions to datetime values you may get very unexpected and often unusable results.
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.