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

All,

If I run below code it works majority of time.

But won't work few times

For example, if the

1. TIME = 15:01:50

TIMEVALUE =151.5

 But looking for 1501.50

 2. TIME = 00:00:09

TIMEVALUE = 0.9

Looking for 0000.09

3. TIME = 09:22:09

TIMEVALUE = 922.9

Looking for 0922.09

 

data WORK.time_test;
    format time time8.;
/*    time = "14:04:46"t;*/
      time=time();
      timevalue = input(strip(hour(time))||strip(minute(time))||strip(.)||strip(round(second(time))),8.2);
  
    put time ;
    put timevalue;
      run;
1 ACCEPTED SOLUTION

Accepted Solutions
BrunoMueller
SAS Super FREQ

Use the NLTIME function (there is also a NLDATE function). See example program below.

 

NLTIME returns a char value, this is converted to a numeric and the Z7.2 will print leading zeros

 

data want;
  do timevalue = "15:01:50"t, "00:00:09"t , "09:22:09"t;
    newTimeValue = nltime(timeValue, '%H%M.%S');
    newTimeValue_n = input(newTimeValue, best8.);
    output;
  end;

  format timevalue tod8. newTimeValue_n z7.2;
run;

 

View solution in original post

3 REPLIES 3
BrunoMueller
SAS Super FREQ

Use the NLTIME function (there is also a NLDATE function). See example program below.

 

NLTIME returns a char value, this is converted to a numeric and the Z7.2 will print leading zeros

 

data want;
  do timevalue = "15:01:50"t, "00:00:09"t , "09:22:09"t;
    newTimeValue = nltime(timeValue, '%H%M.%S');
    newTimeValue_n = input(newTimeValue, best8.);
    output;
  end;

  format timevalue tod8. newTimeValue_n z7.2;
run;

 

s_lassen
Meteorite | Level 14

I would use the TIME. format instead:

data _null_;
  timevalue=time();
  format timevalue time11.2;
  put timevalue=;
run;

The time-value will then display nicely. And you can subtract it from another time-value to get the number of seconds between the two.

 

If you MUST do it the other way, it would be better to do it like this:

data _null_;                                            
  timevalue=time();                                     
  timevalue=hour(timevalue)*10000+minute(timevalue)*100 
            +second(timevalue);                         
  format timevalue z9.2;                                
  put timevalue=;                                       
run;

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