BookmarkSubscribeRSS Feed
india2016
Pyrite | Level 9

03JAN2011:00:00:00.000

which format should I use to read this date ?

 

6 REPLIES 6
art297
Opal | Level 21

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

 

ChrisBrooks
Ammonite | Level 13

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

ballardw
Super User

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.

Reeza
Super User

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

ChrisBrooks
Ammonite | Level 13
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.....
india2016
Pyrite | Level 9

Thanks, everyone

 

 

.

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

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
  • 807 views
  • 2 likes
  • 5 in conversation