DATA Step, Macro, Functions and more

datetime informat: mm/dd/yyyy hh:mm:ss (24 hour time format)

Accepted Solution Solved
Reply
Contributor
Posts: 43
Accepted Solution

datetime informat: mm/dd/yyyy hh:mm:ss (24 hour time format)

We have a data file in csv format and there's a datetime field in mm/dd/yyyy hh:mm:ss (24 hour time format) for which I'm having trouble importing.  Although this seems like a standard datetime format, surprisingly I can't seem to find an informat that works.  If the time was in the AM/PM format I could use ANYDTDTM or MDYAMPM** but the 24 hour time format appears to be problematic.  I'm writing specifications for data users and I'd like it to be as simple as possible (i.e., creating user-defined informat is not an option) and all other date formats are in the mm/dd/yyyy format and all times are in the hh:mm format (24 hour), so I'd like to keep to those standards if possible.  Is there an informat for this I just haven't found yet?

 

Thanks!

Ryan

 

 


Accepted Solutions
Solution
‎04-24-2018 12:18 PM
Super User
Posts: 13,084

Re: datetime informat: mm/dd/yyyy hh:mm:ss (24 hour time format)

Please show what you tried and the log if there are any warnings or errors. And perhaps a line or two of the data file.

 

You might try the ANYDTDTM as ANYDTDTM32. It seems that sometimes for whatever reason that using a longer version of the format works better than a shorter version

View solution in original post


All Replies
Solution
‎04-24-2018 12:18 PM
Super User
Posts: 13,084

Re: datetime informat: mm/dd/yyyy hh:mm:ss (24 hour time format)

Please show what you tried and the log if there are any warnings or errors. And perhaps a line or two of the data file.

 

You might try the ANYDTDTM as ANYDTDTM32. It seems that sometimes for whatever reason that using a longer version of the format works better than a shorter version

Contributor
Posts: 43

Re: datetime informat: mm/dd/yyyy hh:mm:ss (24 hour time format)

It worked!  Thank you.

 

I can import it using the informat you listed but the import transforms it to a new datetime format.  SAS doesn't recognize ANYDTDTM32 as a datetime format in the format statement. How do I keep it in the mm/dd/yyyy hh:mm:ss (24 hour time format) format?

Super User
Posts: 13,084

Re: datetime informat: mm/dd/yyyy hh:mm:ss (24 hour time format)


@Ryanb2 wrote:

It worked!  Thank you.

 

I can import it using the informat you listed but the import transforms it to a new datetime format.  SAS doesn't recognize ANYDTDTM32 as a datetime format in the format statement. How do I keep it in the mm/dd/yyyy hh:mm:ss (24 hour time format) format?


Formats and informats do not always have a corresponding one in the other half of the topic. If DATETIME19. is unacceptable for your appearance then you can roll your own in Proc Format which allows some pretty exotic options for creating odd date or time appearances with a Picture statement.

proc format library=work;
picture dtmmddyy (default=19)
low-high = '%0m/%0d/%Y %0H:%0M:%0S' (datatype=datetime)
. = 'NA'
;
run;
data junk;
   x=dhms(today(),0,0,time());
   format x dtmmddyy.;
run;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 107 views
  • 2 likes
  • 2 in conversation