BookmarkSubscribeRSS Feed
rickpaulos
Obsidian | Level 7

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

 

 

 

 

1 REPLY 1
Cynthia_sas
SAS Super FREQ

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 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=test2;
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 791 views
  • 0 likes
  • 2 in conversation