SAS Programming Professionals,
Did you know that you can easily input a plethora of very messy date values using the ANYDTDTE informat?
This very utilitarian SAS informat can read and extract a host of different date values that are found in real-world data. Here is an example:
input oddates ANYDTDTE32.;
format oddates mmddyy10.;
04/27/11 02:30:08 AM
04/27/2012 02:30:08 AM
proc print noobs data=datefile;
In this contrived example, we are inputting date values that have been stored in 20 different formats. The ANYDTDTE informat interprets the input text lines as date values and stores them as SAS dates in the ODDATES variable. Don’t take my word for it; enter this example into a SAS Display Manager session and take it for a test drive. As you can see, the ANYDTDTE informat is a handy tool to use when you are reading input files with varying or non-traditional date formats.
The ANYDTDTE informat has two sibling informats: ANYDTTME which reads and extracts time values from various date, time and datetime forms; and ANYDTDTM, which reads and extracts datetime values from various date, time and datetime forms. They are also worth looking into!
Best of luck in all of your SAS endeavors!
(aka Michael A. Raithel)
Excerpt from the book: Did You Know That? Essential Hacks for Clever SAS Programmers
I plan to post each and every one of the hacks in the book to social media on a weekly basis. Please pass them along to colleagues who you know would benefit.