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

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.);

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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