- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I know it would be a very long list but. Is there a list of all possible dates, times and datetimes formats with the corresponding SAS INFORMAT to use for each? The SAS documentation for each informat isn't all that helpful. It's mostly trial and error and trial and error and on and on to find on that works if it one exists. Reading in as char and parsing gets rather tedious and is prone to data induced errors.
Right now I'm trying to find the SAS informat to read datetimes like this from a text file:
07-Apr-2015 11:32 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi:
Most of the time the "ANY" informats work, ANYDTDTM, for example. Look at the list here: http://go.documentation.sas.com/?docsetId=allprodslang&docsetTarget=syntaxByType-informat.htm&docset... the "ANY" informats are at the top of the page and when you click on a format name, there is usually an example that shows which types of dates you can use with the informat.
For me, the ANYDTDTM usually works OK either in an INPUT statement or an INPUT function, as long as my date in the data matches one of their examples.
cynthia
For example, this worked for me using an INPUT function with ANYDTDTM -- and for TEST2, it also worked in an INPUT statement:
data testinformat;
length example $1 datestr $21;
infile datalines dlm=',';
input example $ datestr $;
dateinfo = input(datestr,anydtdtm.);
format dateinfo datetime21.;
return;
datalines;
a,07-Apr-2015 11:32 PM
b,07APR2015
d,07APR2015:23:32:08
d,04072015
e,04/07/15
f,04-15
g,APR2015
h,20150407
i,April 7 2015
;
run;
proc print data=testinformat;
run;data test2; length example $1 ; infile datalines dlm=','; input example $ dateinfo : anydtdtm.; format dateinfo datetime21.;return;datalines;a,07-Apr-2015 11:32 PMb,07APR2015d,07APR2015:23:32:08d,04072015e,04/07/15f,04-15g,APR2015h,20150407i,April 7 2015;run; proc print data=test2;run;