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

 

Hi all,

 

I have a variable of text data type with data value looks like 'username1 17/04/28 13:34:44'. 

the text string is the username and followed by the date (YY/MM/DD) and time (24 hour format).

 

I want to convert this variable into a datetime field looks like '28APR2017:13:34:44' of data type "datetime20." which I will use later in the program to calculate the time interval.

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

HI @zimcom   Will this do?


data test;
have='username1 17/04/28 13:34:44';
want=dhms(input(scan(have,2,' '),yymmdd8.),0,0,0) +
  input(scan(have,-1,' '),time10.);
format want datetime20.;
run;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

HI @zimcom   Will this do?


data test;
have='username1 17/04/28 13:34:44';
want=dhms(input(scan(have,2,' '),yymmdd8.),0,0,0) +
  input(scan(have,-1,' '),time10.);
format want datetime20.;
run;
zimcom
Pyrite | Level 9

@novinosrin Thank you so much!!

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