DATA Step, Macro, Functions and more

Date formats

Reply
Frequent Contributor
Posts: 79

Date formats

03JAN2011:00:00:00.000

which format should I use to read this date ?

 

Super User
Posts: 8,216

Re: Date formats

Posted in reply to india2016

Depends upon what you want. That is a datetime, not a date. If you want to capture all three you could use something like:

data have;
  input dt datetime22.;
  format date date9.;
  format time time5.;
  date=datepart(dt);
  time=timepart(dt);
  cards;
03JAN2011:00:00:00.000
;

Art, CEO, AnalystFinder.com

 

Valued Guide
Posts: 596

Re: Date formats

Posted in reply to india2016

You need an informat to read data not a format - try datetime22. (Untested)

Super User
Posts: 13,941

Re: Date formats

Posted in reply to india2016

If all of the values have the same "time", especially of :00:00:00.000 I would use a DATE9. informat to read the date and discard the time part.

Don't forget to set a display format so humans can see the date in a useable form.

Super User
Posts: 24,010

Re: Date formats

Posted in reply to india2016

When in doubt try ANYDTDTM for datetime and ANYDTDTE for dates.

Valued Guide
Posts: 596

Re: Date formats

Posted in reply to india2016
The only note of caution I'd sound about ANYDTDTM and ANYDTDTE is that they are dependant on the correct Locale being set. I learned that the hard way a few years ago when working on a server in the U.K. where unknown to me the Locale had been set to US which led to some correct dates, some incorrect dates and some errors. It puzzled me for quite a while before I realised what was going on.....
Frequent Contributor
Posts: 79

Re: Date formats

Posted in reply to ChrisBrooks

Thanks, everyone

 

 

.

I used Datetime22.3 format and it successfully reads that observation.

Ask a Question
Discussion stats
  • 6 replies
  • 189 views
  • 2 likes
  • 5 in conversation