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

Hi all,

 

Currently the variable is formated as datetime22.  like 01JAN2021:03:20:55. 

 

How can I get the time out of this field in the output below ?

 

03:20:55 

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
EPANG1
Fluorite | Level 6
Here is the solution. Thanks Koen.

Re: how to separate variable into date and time
data _NULL_;
a='01JAN2021:03:20:55'dt; put a= datetime22.;
b=datepart(a) ; put b= date9.;
c=timepart(a) ; put c= time8.;
run;
/* end of program */
Koen

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26

In a data step, assuming your variable is named DATE

 

time=timepart(date);
format time time8.;
--
Paige Miller
sbxkoenk
SAS Super FREQ
data _NULL_;
 a='01JAN2021:03:20:55'dt; put a= datetime22.;
 b=datepart(a)           ; put b= date9.;
 c=timepart(a)           ; put c= time8.;
run;
/* end of program */

Koen

EPANG1
Fluorite | Level 6
Here is the solution. Thanks Koen.

Re: how to separate variable into date and time
data _NULL_;
a='01JAN2021:03:20:55'dt; put a= datetime22.;
b=datepart(a) ; put b= date9.;
c=timepart(a) ; put c= time8.;
run;
/* end of program */
Koen
PaigeMiller
Diamond | Level 26

@EPANG1 

You need to mark the solution from @sbxkoenk as correct, not your own post where you repeat his solution.

--
Paige Miller
sbxkoenk
SAS Super FREQ

Especially as it would be my 100th solution. 😉

No worries!

I guess @EPANG1 will do it correct next time.

 

Koen

EPANG1
Fluorite | Level 6

Apologies as I only see your answer in my inbox, but not displaying in the community forum. that's why I have copy the response again. 

sbxkoenk
SAS Super FREQ

Again, no worries!

Maybe you had to refresh / reload the browser page you were looking at (?).

My answer is definitely in the thread.

Koen

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 7 replies
  • 1572 views
  • 0 likes
  • 3 in conversation