There is a column of DATE with diff formats, I want to write a dynamic code that can read all these dates:
DATE
20112017 (DDMMYYYY)
21072017 (DDMMYYYY)
09212017 (MMDDYYYY)
01JAN2017 (DDMONYYYY)
Please help.
data have;
input DATE : $20. format : $20. ;
want=inputn(date,format);
format want date9.;
cards;
20112017 DDMMYY10.
21072017 DDMMYY10.
09212017 MMDDYY10.
01JAN2017 DATE9.
;
If some of the dates have month before day, and other dates have day before month, then you are in a situation where no global answer exists. Although 20112017 must be day 20 of month 11 (because it can't be day 11 of month 20), there is no way for anyone to know which is the day and which is the month if your input data 04112017.
So, you have to make a decision about how these inputs should be handled. This really isn't a SAS question any more, this is a question for you to decide.
Try the ANYDTDTE. informat.
Then look at results very closely because it is very likely to make assumptions, the similar to the way you would looking at some of those values.
I hope you don't have any 6-digit versions as with inconsistent layouts you cannot tell what 010203 would actually represent.
data have;
input DATE : $20. format : $20. ;
want=inputn(date,format);
format want date9.;
cards;
20112017 DDMMYY10.
21072017 DDMMYY10.
09212017 MMDDYY10.
01JAN2017 DATE9.
;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.