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

I'm dealing with an API that returns timestamps as strings such as "Wed Apr 30 13:44:54 GMT 2025"

 

ANYDTDTM. informat does not properly parse the timestamp from the string.

 

The construct looks like it is from Java via

DateTimeFormatter.ofPattern("E M d k:m:s 'GMT' y")

 

Is there a SAS informat that directly reads the string?

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

First, I would say that you need to describe what you mean by "ANYDTDTM. informat does not properly parse the timestamp from the string.".

 

This code:

data junk;
   x= "Wed Apr 30 13:44:54 GMT 2025";
   y= input(x,anydtdtm32.);
   format y datetime20.;
run;

yields a value of 30APR2025:13:44:54 for Y, which looks like the "time" was parsed correctly. Note that if you do not provide a width then the informat uses a default width of 19. Your value as shown is 28 characters long. So you need to provide a width at least of 28. There are some cases where the width specified may need to be a few characters longer than the value to work properly, I can't remember an exact value but remember at least a few cases where a width of 32 worked where the value was a bit less and exact width didn't.

 

If you mean that the Timezone is not included and is what you need then you need to say so.

There are a number of FORMATS that display Timezone offsets. look in the documentation of the various B8601 and E8601 formats.

 

View solution in original post

1 REPLY 1
ballardw
Super User

First, I would say that you need to describe what you mean by "ANYDTDTM. informat does not properly parse the timestamp from the string.".

 

This code:

data junk;
   x= "Wed Apr 30 13:44:54 GMT 2025";
   y= input(x,anydtdtm32.);
   format y datetime20.;
run;

yields a value of 30APR2025:13:44:54 for Y, which looks like the "time" was parsed correctly. Note that if you do not provide a width then the informat uses a default width of 19. Your value as shown is 28 characters long. So you need to provide a width at least of 28. There are some cases where the width specified may need to be a few characters longer than the value to work properly, I can't remember an exact value but remember at least a few cases where a width of 32 worked where the value was a bit less and exact width didn't.

 

If you mean that the Timezone is not included and is what you need then you need to say so.

There are a number of FORMATS that display Timezone offsets. look in the documentation of the various B8601 and E8601 formats.

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 657 views
  • 3 likes
  • 2 in conversation