Desktop productivity for business analysts and programmers

How do I convert string HH:MM into time HH:MM format?

Accepted Solution Solved
Reply
Contributor
Posts: 23
Accepted Solution

How do I convert string HH:MM into time HH:MM format?

[ Edited ]

I have a column with HH:MM in a string format, I would like it to be converted into HHMw.d time format.

 

In EG, I go to Query Builder and advanced expression with "INPUT(t1.time_v2, HHMMw.)", it created a new variable but they are all missing (.).


Accepted Solutions
Solution
‎08-02-2017 01:08 PM
Super User
Posts: 19,870

Re: How do I convert string HH:MM into time HH:MM format?


KubiK888 wrote:
Thanks, but it turns it into 5-digit number. For example "7:57" into 28620.

That's likely correct. Now you need to apply a format to it as well, TIME. 

 

SAS stores times as the number of seconds and dates as the number of days. 

View solution in original post


All Replies
PROC Star
Posts: 307

Re: How do I convert string HH:MM into time HH:MM format?

Are you actually putting "w" as the length? That should actually be a number or potentially nothing. You're not getting any kind of note or error?

Contributor
Posts: 23

Re: How do I convert string HH:MM into time HH:MM format?

[ Edited ]
Posted in reply to collinelliot

I am not getting any error. But there is note: Invalid string for 

 

234 t1.time_v2,
235 /* time_v3 */
236 (INPUT(t1.time_v2, HHMM.)) AS time_v3
237 FROM WORK.QUERY_FOR_UNDERSTANDI_0003 t1;

 

And with and without "w" doesn't make a difference, just create a new column with all empty value.

Super User
Posts: 19,870

Re: How do I convert string HH:MM into time HH:MM format?

Are you sure it's a string format? Can you show a proc contents and a few values?

Super User
Posts: 11,343

Re: How do I convert string HH:MM into time HH:MM format?

Try TIME5. instead of HHMMw. if you only have hour and minutes.

HHMMw. is a display format, not an informat.

 

I would expect an error similar to this:

355  data junk;
356     time_v2 = "12:34";
357     tt =INPUT(time_v2, HHMM.);
                           -----
                           485
NOTE 485-185: Informat HHMM was not found or could not be loaded.

358  run;
Contributor
Posts: 23

Re: How do I convert string HH:MM into time HH:MM format?

Thanks, but it turns it into 5-digit number. For example "7:57" into 28620.
Solution
‎08-02-2017 01:08 PM
Super User
Posts: 19,870

Re: How do I convert string HH:MM into time HH:MM format?


KubiK888 wrote:
Thanks, but it turns it into 5-digit number. For example "7:57" into 28620.

That's likely correct. Now you need to apply a format to it as well, TIME. 

 

SAS stores times as the number of seconds and dates as the number of days. 

☑ This topic is solved.

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

Discussion stats
  • 6 replies
  • 302 views
  • 0 likes
  • 4 in conversation