BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
JillChen0131
Fluorite | Level 6

I have some time in character format, like below:

04:25

8:37

11:30

9:14

I would like to show all time in HH:MM format, if only one digit, add a "0" in the beginning. 

Can anyone help with this?

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Here is an example:

data example;
   input char $;
   timevar = input(char,time.);
   format timevar tod5.;
datalines;
04:25
8:37
11:30
9:14
;

Create a new variable with the input function (or read it with the TIME. informat when reading the data into SAS) then apply the TOD5. format. The TOD (time of day) format will default to 8 characters including seconds, using the 5 shows HH:MM only.

 


@JillChen0131 wrote:

I have some time in character format, like below:

04:25

8:37

11:30

9:14

I would like to show all time in HH:MM format, if only one digit, add a "0" in the beginning. 

Can anyone help with this?


 

View solution in original post

1 REPLY 1
ballardw
Super User

Here is an example:

data example;
   input char $;
   timevar = input(char,time.);
   format timevar tod5.;
datalines;
04:25
8:37
11:30
9:14
;

Create a new variable with the input function (or read it with the TIME. informat when reading the data into SAS) then apply the TOD5. format. The TOD (time of day) format will default to 8 characters including seconds, using the 5 shows HH:MM only.

 


@JillChen0131 wrote:

I have some time in character format, like below:

04:25

8:37

11:30

9:14

I would like to show all time in HH:MM format, if only one digit, add a "0" in the beginning. 

Can anyone help with this?


 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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