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

Hello

I have a numeric value that represent time

for example 101600  is 10:16:00  (hour 10  ,mimutes 16,seconds 0)

How can I convert it into time variable please?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Use PUT() to create a string, CATX() to make it into a proper format for INPUT():

data _null_;
num = 101600;
length string $8;
string = put(num,z6.);
string = catx(":",substr(string,1,2),substr(string,3,2),substr(string,5,2));
time = input(string,time8.);
format time time8.;
put time=;
run;

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

Use PUT() to create a string, CATX() to make it into a proper format for INPUT():

data _null_;
num = 101600;
length string $8;
string = put(num,z6.);
string = catx(":",substr(string,1,2),substr(string,3,2),substr(string,5,2));
time = input(string,time8.);
format time time8.;
put time=;
run;
ballardw
Super User

Or get the numeric parts of the value and use HMS function.

data junk;
   num = 101600;
   time = hms(int(num/10000),mod(int(num/100),100),mod(num,100)); 
   format time time8.;
run;

@Ronein wrote:

Hello

I have a numeric value that represent time

for example 101600  is 10:16:00  (hour 10  ,mimutes 16,seconds 0)

How can I convert it into time variable please?

 


 

FreelanceReinh
Jade | Level 19

If it's a time of day (i.e., at most 235959), you can also use the B8601TM. informat:

time=input(put(num,z6.),b8601tm.);

 

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
  • 3 replies
  • 3861 views
  • 7 likes
  • 4 in conversation