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!!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 6 replies
  • 934 views
  • 1 like
  • 2 in conversation