Thanks all for the feedback. I am trying to avoid using a user defned function, and want to accomplish this with informats.
I've combined several of the suggestions and have come up with this:
(Thanks @Kurt_Bremser for pointing out anydtdte's, ummm, "feature").
data infmt;
retain fmtname "yyyy" type "I" ;
do start=0001 to 9999;
label = mdy(1,1,start);
output ;
end ;
run;
proc format cntlin = infmt ; run ;
proc format;
invalue messyDate
"/^\d{1,2}\D\d{1,2}\D\d{4}/" (regexp) = [mmddyy10.]
"/^\d{4}/" (regexp) = [yyyy.]
other = [anydtdte32.]
;
run;
data test;
infile datalines truncover dlm="|";
input datestring :$64.; format datestring $64.;
formatedDate = input(datestring, messyDate.); format formatedDate date11.;
cards;
12/12/2017
12/10/2017
10/12/2017
10/13/2017
03/01/2015
03-01-2015
03.01.2015 03 01 2015
3/1/2015
03/2015
3/2015
2017
1March2015
01March2015
1MAR2015
Mar 01 2015
MAR 01, 2015
March 1, 2015
March 1 2015
Mar 2015
March 2015
March, 2015
;
run;
proc print data=test; run;
As you can see, I was a little coy regarding how messy the data are. This seems to work with the exception of the last two rows, i.e. when the full month is spelled out but no day is given.
... View more