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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1340 views
  • 5 likes
  • 4 in conversation