BookmarkSubscribeRSS Feed
D_W
Calcite | Level 5 D_W
Calcite | Level 5

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!

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Could it be that 

 

put(time,$6.)

is where you lose the milliseconds?

--
Paige Miller
SuryaKiran
Meteorite | Level 14

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;
Thanks,
Suryakiran
PGStats
Opal | Level 21

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;
PG
D_W
Calcite | Level 5 D_W
Calcite | Level 5

Thank you very much! This worked perfectly. 

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

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 4 replies
  • 1751 views
  • 1 like
  • 4 in conversation