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
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
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
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?
@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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.