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;
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;
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;
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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.