DATA Step, Macro, Functions and more

Need to convert character to date and time

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 84
Accepted Solution

Need to convert character to date and time

Hi all,

 

I have a variable Time, but its attributes is character. The example is 

 

12/09/2016 05:15:00 AM

12/21/2016 05:23:00 AM

10/27/2016 08:35:00 AM

 

How can I convert this character to date and time, and still in one column? Since I have AM or PM there, is it possible?

 

Thanks,

Chen


Accepted Solutions
Solution
‎03-13-2017 10:15 AM
Super User
Super User
Posts: 7,997

Re: Need to convert character to date and time

Assuming that it is mdy date, then:

data want;
  txt="12/09/2016 05:15:00 AM";
  dt=input(txt,mdyampm24.);
  format dt datetime.;
run;

View solution in original post


All Replies
Solution
‎03-13-2017 10:15 AM
Super User
Super User
Posts: 7,997

Re: Need to convert character to date and time

Assuming that it is mdy date, then:

data want;
  txt="12/09/2016 05:15:00 AM";
  dt=input(txt,mdyampm24.);
  format dt datetime.;
run;
Frequent Contributor
Posts: 84

Re: Need to convert character to date and time

Hi RW9,

 

That really works!!!

Thanks so much for your help!

 

Chen

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 148 views
  • 1 like
  • 2 in conversation