BookmarkSubscribeRSS Feed
kbrennan
Calcite | Level 5

I am trying to convert the time from a column called Start_Time to a number.

An example is (In Military Time) 6:24:43 to the number 6. 

Once I get the number I want to put that number into a new Column called New_Time.

 

 

 

7 REPLIES 7
noling
SAS Employee

Are you trying to pull the just the hour? There is an hour function.


Register today and join us virtually on June 16!
sasglobalforum.com | #SASGF

View now: on-demand content for SAS users

kbrennan
Calcite | Level 5

Thanks for the info.

How do use that column "start_time" instead of quantifying each one such as the 6:24:43 ?

Kurt_Bremser
Super User

To use an existing dataset, use the set statement:

/* make up some sample data */
data have;
input start_time :$8.;
cards;
6:24:43
;
run;

data want;
set have;
new_time = input(start_time,time8.);
format new_time time8.;
run;
noling
SAS Employee

If you only want the hour and want to read from the existing data set, use KurtBremser's SET statement with the HOUR function:

 

/* make up some sample data */
data have;
input start_time :$8.;
cards;
6:24:43
23:11:11
01:40:30
;
run;

data want;
	set have;
	new_time = hour(input(start_time,time8.));
run;

Register today and join us virtually on June 16!
sasglobalforum.com | #SASGF

View now: on-demand content for SAS users

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 7 replies
  • 4353 views
  • 0 likes
  • 3 in conversation