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

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Onyx | Level 15

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;

(example 7) https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/n01lvjtpz3ewuhn1cvj3x4yhzyul...

 

Bart

 

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User

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.

yabwon
Onyx | Level 15

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;

(example 7) https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/n01lvjtpz3ewuhn1cvj3x4yhzyul...

 

Bart

 

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



mmohotsi
Obsidian | Level 7

The solution worked well

ballardw
Super User

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 2331 views
  • 1 like
  • 4 in conversation