Hi, I currently have time variables listed in a table and have been trying to convert these time variables that are currently in decimal form to a Time12.6 format. For example, I would like 93501.5373 as 9:35:01.5373
The code I have been using so far has cut off the millisecond numbers and only reported to the seconds:
data test; set test;
new_time = input(put(time,$6.),hhmmss12.);
format test_time time12.6;
run;
If anyone has a solution that would be greatly appreciated. Thank you!
Could it be that
put(time,$6.)
is where you lose the milliseconds?
Hi,
You can use HMS(<hours>,<minutes>,<seconds>) function. You may need to extract the hours carefully (adding leading zeros might help).
data want;
format Time_Formated time12.6;
time=93501.5373;
Hr=input(substr(put(time,z11.4),1,2),2.);
Min=input(substr(put(time,z11.4),3,2),2.);
Sec=input(substr(put(time,z11.4),5),7.4);
Time_Formated=hms(Hr,Min,Sec);
run;
No need to convert to characters, use math:
data want;
format Time_Formated time12.6;
time=93501.5373;
Time_Formated=hms(floor(time/10000), floor(mod(time,10000)/100), mod(time,100));
run;
Thank you very much! This worked perfectly.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.