BookmarkSubscribeRSS Feed
Ying
Fluorite | Level 6

Hello,

How to format datetime to CCYYMMDD_HHMM?  I can cat a string for YYMMDD_HHMM, but I have no idea about CC (century).  Would I have any idea from you?

Thank you!

Yvonne

6 REPLIES 6
Keith
Obsidian | Level 7

Create a picture format using the required directives to produce the result you want.  You can then either format the existing column, or create a character string using the PUT statement.

proc format;

picture dtfmt low-high = '%Y%0m%0d_%0H%0M'

  (datatype=datetime);

run;

data want;

a='18jul2012:08:50'dt;

format a dtfmt.;

b=put(a,dtfmt.);

run;

Ksharp
Super User

What is your sample data and output you need ?

Ying
Fluorite | Level 6

system time, such as today()

advoss
Quartz | Level 8

I agree with Keith. Additionally, you probably want to use datetime() rather than today() if you want hours and minutes as well as date.

Haikuo
Onyx | Level 15

I am not sure if understand your question.  For example 'today', 20120718, '20' marks CC(century), '12' marks YY, etc. What is the question then? If you are asking why '20' denotes 21st century, well that is way it is, as it started out as 1st instead of 0th century (A.D).

Haikuo

Ying
Fluorite | Level 6

Thank you all for helping me.  Hai.Kuo is right that YYYY = CCYY.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 6 replies
  • 2432 views
  • 0 likes
  • 5 in conversation