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

Hello, I have in a string value the date time in this format  "2018-09-04T14:11:58.000Z".      I've been trying the SAS ISO formats within an INPUT statement but can't identify the correct format from the support documentation  SAS ISO Support Documentation

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
RB1Kenobi
Quartz | Level 8

I had some success with the code below

data textstring;
iso = '2018-09-04T14:11:58.000Z'; output;
iso = '2019-10-01T14:11:58.000Z'; output;
iso = '2018-09-04T14:11:58.000Z'; output;
iso = '2019-10-01T14:11:58.000Z'; output;
iso = '2019-10-01T14:44:42.000Z'; output;
run;

data t1;
set textstring;
informat t1  E8601DT16.;
format t1  E8601DT16.   t2 date9.   t3 time5.;

t1= input(iso,E8601DT16.);
t2=datepart(t1);
t3=timepart(t1);
run;

View solution in original post

6 REPLIES 6
Astounding
PROC Star
Try:

datevar = input(charvar, yymmdd10.);

You would probably want to apply a format to DATEVAR.
RB1Kenobi
Quartz | Level 8
Thank you for your assistance. I hadn't seen these before selecting the "solution" for the thread.
Kurt_Bremser
Super User

See here:

data test;
dt_char = "2018-09-04T14:11:58.000Z";
dt_num = input(dt_char,e8601dz24.);
format dt_num e8601dx32.3;
run;

Result:

1	2018-09-04T14:11:58.000Z	2018-09-04T16:11:58.000+02:00

(Austria, DST)

RB1Kenobi
Quartz | Level 8
Thanks for your assistance. I hadn't seen these before selecting the "solution" for the thread.
RB1Kenobi
Quartz | Level 8
To add some context, I know it could be handled using MDY or similar but I want to transform the field within a JSON Map so to know the exact informat/format would help to keep the syntax simple.
RB1Kenobi
Quartz | Level 8

I had some success with the code below

data textstring;
iso = '2018-09-04T14:11:58.000Z'; output;
iso = '2019-10-01T14:11:58.000Z'; output;
iso = '2018-09-04T14:11:58.000Z'; output;
iso = '2019-10-01T14:11:58.000Z'; output;
iso = '2019-10-01T14:44:42.000Z'; output;
run;

data t1;
set textstring;
informat t1  E8601DT16.;
format t1  E8601DT16.   t2 date9.   t3 time5.;

t1= input(iso,E8601DT16.);
t2=datepart(t1);
t3=timepart(t1);
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
  • 6 replies
  • 914 views
  • 2 likes
  • 3 in conversation