DATA Step, Macro, Functions and more

CCYYMMDD_HHMM string

Reply
Contributor
Posts: 31

CCYYMMDD_HHMM string

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

Regular Contributor
Posts: 151

Re: CCYYMMDD_HHMM string

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;

Super User
Posts: 9,681

Re: CCYYMMDD_HHMM string

What is your sample data and output you need ?

Contributor
Posts: 31

Re: CCYYMMDD_HHMM string

system time, such as today()

Frequent Contributor
Posts: 91

Re: CCYYMMDD_HHMM string

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

Respected Advisor
Posts: 3,124

Re: CCYYMMDD_HHMM string

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

Contributor
Posts: 31

Re: CCYYMMDD_HHMM string

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

Ask a Question
Discussion stats
  • 6 replies
  • 355 views
  • 0 likes
  • 5 in conversation