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

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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