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.

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
  • 4 replies
  • 2172 views
  • 1 like
  • 4 in conversation