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

Hi everyone,

does somebody now how to read a datetime string like "2023-04-30T00:00:00.000+02:00" into a sas table?

I'm looking for a suitable informat. Something like anydtdtm40. (but this doesn't work).

I only need the date, by the way, time is irrelevant for me.

Thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

YYMMDD seems to work fine.

data test;
  infile cards dsd truncover ;
  input id date :yymmdd. ;
  format date yymmdd10.;
cards;
1,"2023-04-30T00:00:00.000+02:00"
;
Obs    id          date

 1      1    2023-04-30

View solution in original post

8 REPLIES 8
PaigeMiller
Diamond | Level 26

Perhaps this table will be of use: https://documentation.sas.com/doc/en/pgmmvacdc/9.4/leforinforref/n09mk4h1ba9wp1n1tc3e7x0eow8q.htm#p0...

 

data have;
    dt="2023-04-30T00:00:00.000+02:00";
    dt_new=input(dt,E8601DZ30.3);
    format dt_new datetime19.;
run;
--
Paige Miller
Preguntarius
Fluorite | Level 6

Thanks!

Unfortunately, it doesn't work when I read the csv file.

So this part delievers only missings.

 

data xy;
infile "/----.csv" informat ULTIMOTS E8601DZ30.3; format ULTIMOTS datetime19.; input ULTIMOTS ; run;
PaigeMiller
Diamond | Level 26

@Preguntarius wrote:

Thanks!

Unfortunately, it doesn't work when I read the csv file.

So this part delievers only missings.

 

data xy;
infile "/----.csv" informat ULTIMOTS E8601DZ30.3; format ULTIMOTS datetime19.; input ULTIMOTS ; run;

When something doesn't work, show us the LOG. (All of the log for this data step, every single line for this data step).

--
Paige Miller
Tom
Super User Tom
Super User

why would you ask it to imply a decimal point?

PaigeMiller
Diamond | Level 26

But using YYMMDD10. does not take into account the adjustment made for the time zone offset. So I cannot see how that is a correct answer.

 

 

--
Paige Miller
Tom
Super User Tom
Super User

@PaigeMiller wrote:

But using YYMMDD10. does not take into account the adjustment made for the time zone offset. So I cannot see how that is a correct answer.

 

 


That is for the original poster to decide. 

If they don't care about the time of day then they probably do not care about a 2 hour difference either.   It might be that every record has the same midnight with 2 HR offset because the values were generated from a system that only has timestamp data type.

 

But it it no possible to tell from a sample size of one.

data test;
  infile cards dsd truncover ;
  input id str :$29. ;
  dt = input(str,e8601dz29.);
  date1 = input(str,yymmdd10.);
  date2 = datepart(dt);
  format dt datetime19. date: yymmdd10.;
cards;
1,"2023-04-30T00:00:00.000+02:00"
;
Obs    id                 str                                  dt         date1         date2

 1      1    2023-04-30T00:00:00.000+02:00     29APR2023:22:00:00    2023-04-30    2023-04-29
Tom
Super User Tom
Super User

YYMMDD seems to work fine.

data test;
  infile cards dsd truncover ;
  input id date :yymmdd. ;
  format date yymmdd10.;
cards;
1,"2023-04-30T00:00:00.000+02:00"
;
Obs    id          date

 1      1    2023-04-30
Preguntarius
Fluorite | Level 6
That's it, thanks a lot!

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 8 replies
  • 1264 views
  • 4 likes
  • 3 in conversation