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

Dear community,

 I have a read in date and time field as below

XNDATXNTIM
Jun 7 2015 12:00AM17:53:00

of which XNDAT is 'Text ' and XNTIM as 'Num'

 

How can I combine them into a long SAS datetime

 

Your help is greatly appreciated and thank you

 

new SAS learner

zimcom 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data w;
k='Jun 7 2015 12:00AM';
k1='17:53:00't;
k2=input(k,anydtdte20.);
k3=dhms(k2,0,0,0)+k1;
format  k3 datetime20.;
run;

View solution in original post

6 REPLIES 6
novinosrin
Tourmaline | Level 20
data w;
k='Jun 7 2015 12:00AM';
k1='17:53:00't;
k2=input(k,anydtdte20.);
k3=dhms(k2,0,0,0)+k1;
format  k3 datetime20.;
run;
zimcom
Pyrite | Level 9

It works perfect, you are the best!

 

Thank you so much!!

 

zimcom

zimcom
Pyrite | Level 9

one more quetion, how to deal with these data below, combine then into one SAS long date? 

 

XTDATXTTIM
Jun 7 2015 12:00AM1/1/0001 6:15:00 PM

 

Thank you!

novinosrin
Tourmaline | Level 20
data w;
k='Jun 7 2015 12:00AM';
k1='1/1/0001 6:15:00 PM';
k2=input(k,anydtdte20.);
k3=input(k1,anydtdtm21.);
k4=dhms(k2,0,0,0)+timepart(k3);
format k2 date9. k3 k4 datetime20.;
run;
novinosrin
Tourmaline | Level 20

slight correction to the above:

 

data w;
k='Jun 7 2015 12:00AM';
k1='1/1/0001 6:15:00 PM';
k2=input(k,anydtdtm21.);
k3=input(k1,anydtdtm21.);
k4=k2+timepart(k3);
format k2 date9. k3 k4 datetime20.;
run;
zimcom
Pyrite | Level 9

you are absolutely awesome and helpful!!

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
  • 6 replies
  • 1867 views
  • 1 like
  • 2 in conversation