DATA Step, Macro, Functions and more

Simple Date Informat Question

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 11
Accepted Solution

Simple Date Informat Question

[ Edited ]

Hello everyone,

 

I'm just started learning SAS, and got a simple question about date informat (don't know if it's too simple or too stupid).

 

Since ANYDTDTEw informat can read any date styles, why does SAS have so many other date informats, like mmddyy, ddmmyy,date, julian...)? is it nevessary to keep them? In my opinion, actually very few people like to use the simple way (ANYDTDTEw), is there any reason for this? 

 

thanks,


Accepted Solutions
Solution
‎03-18-2016 03:28 PM
Super User
Posts: 10,500

Re: Simple Date Informat Question about date informat

If the data is supposed to be in one format when received and does not match the specified format the resulting missing values help identify records with the problem for correction.

Also with two digit years in some formats you don't want anydt guesing. If you have a value like 020104 that you know is supposed to be 4 Jan 2002 the anydt algorithm is going to get Feb 1 2004 or 2 Jan 2004 depending on locale settings. Not that I like data in that format but it occurs.

View solution in original post


All Replies
Super User
Posts: 17,819

Re: Simple Date Informat Question about date informat

When you use ANYDTDTE you're allowing SAS to guess for you what the date informat actually is, but if you know what it is, it's better to specify it. This way, any dates that are enterered incorrectly will return a missing value or error. 

 

Also, ANYDTDTE doesn't recognize all date informats. 

 

And finally, ANYDTDTE was introduced in SAS 9, so it hasn't always existed and the other ones are required for backwards compatability. 

 

Here's a paper on it from a few years ago:

http://support.sas.com/resources/papers/proceedings11/117-2011.pdf

 

 

Solution
‎03-18-2016 03:28 PM
Super User
Posts: 10,500

Re: Simple Date Informat Question about date informat

If the data is supposed to be in one format when received and does not match the specified format the resulting missing values help identify records with the problem for correction.

Also with two digit years in some formats you don't want anydt guesing. If you have a value like 020104 that you know is supposed to be 4 Jan 2002 the anydt algorithm is going to get Feb 1 2004 or 2 Jan 2004 depending on locale settings. Not that I like data in that format but it occurs.

Trusted Advisor
Posts: 1,248

Re: Simple Date Informat Question

Further to the comments provided, the ANYDTDTEw informat is very useful when you may have different format layouts in the same column.

 

The way in which SAS determines the layout ie/ Month Day Year or Day Month Year etc is based on your SAS system locale and datestyle options. It is mentioned in the paper @Reeza references and I spoke about it at our local SAS user group meeting a while ago too - http://www.sascommunity.org/mwiki/images/a/a6/2013-09-26-QUESTTipsAndTechniques-MichelleHomes.pdf

 

I found that not many people know about this very useful informat as they may copy/paste existing code. It can be extremely useful for free-format date fields where the date layout can change in the source file.

 

Kind Regards,

Michelle

Occasional Contributor
Posts: 11

Re: Simple Date Informat Question

thanks, very helpful.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 232 views
  • 2 likes
  • 4 in conversation