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-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

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

Browse our catalog!

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