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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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