BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ryanb2
Quartz | Level 8

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

3 REPLIES 3
ballardw
Super User

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

Ryanb2
Quartz | Level 8

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?

ballardw
Super User

@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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 5845 views
  • 4 likes
  • 2 in conversation