BookmarkSubscribeRSS Feed
Pandu2
Obsidian | Level 7
Hi all,
I've a character value which is like "2012-07-07T20:44:30.293Z". I would like to change this format to datetime
Required : 2012-07-07T20:44:30.293Z
Thanks.
6 REPLIES 6
sbxkoenk
SAS Super FREQ

Hello,

 

What is 'Z'?

data _NULL_;
 a="2012-07-07T20:44:30.293Z";
 b=input(scan(a,1,'T'),YYMMDD10.); put b= date9.;
 c=input(compress(scan(a,2,'T'),'Z'),time12.3); put c= time12.3;
 d=b*24*60*60 + c; put d= datetime22.3;
run;
/* end of program */

Koen

Pandu2
Obsidian | Level 7
Z refers to ZULU
Reeza
Super User

That's an ISO date and there should be informats to handle it directly. 

 

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/leforinforref/n09tmeo4t9edo2n145twyoew1txu.ht...

 

data demo;
 a="2012-07-07T20:44:30.293Z";
 b=input(a, B8601DZ.);
 format b B8601DZ.;
run;

proc print;run;

@Pandu2 wrote:
Hi all,
I've a character value which is like "2012-07-07T20:44:30.293Z". I would like to change this format to datetime
Required : 2012-07-07T20:44:30.293Z
Thanks.

 

sbxkoenk
SAS Super FREQ

@Reeza : thanks for learning me something new.

@Pandu2 : sorry for my earlier reply which was of little or no use to you.

Koen

Kurt_Bremser
Super User

I would rather use the extended ISO 8601 formats/informats:

data demo;
 a="2012-07-07T20:44:30.293Z";
 b=input(a,e8601DZ.);
 format b e8601DZ.;
run;

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 270 views
  • 5 likes
  • 4 in conversation