how to convert minutes from midnight to regular time

Reply
Occasional Learner
Posts: 1

how to convert minutes from midnight to regular time

Hi,

I imported a CSV file in SAS. One of the columns in the file has time as minutes from midnight. Example: 5:00AM would be 300. Its calculated as (5*60). 4:30PM would be ((16*60)+30)=990. Now I need to convert this minutes from midnight column to a regular time column that would look like 05:00:00 or 16:30:00.

How should I do this?

 

I am working on SAS Studio 3.3.

Super User
Posts: 11,134

Re: how to convert minutes from midnight to regular time

Is this data already in as SAS dataset? If you used the import wizard or proc import SAS may have correctly read the data as a time variable. Run Proc contents or look up the variable properties. If either says that you have a format like Time. or TimeAMPM then the variable.

 

If not multiply the value by 60. SAS time variables are kept in seconds. So if you have minutes from midnight then minutes*60 is the SAS time variable.

OR use the function HMS which turns hours, minutes and seconds into time variable.

 

Time = hms(0,minutesfrommidnight,0); /* the zeroes are because you don't have actual hours or second values*/

 

Assign an appropriate format so that the value displays as

Ask a Question
Discussion stats
  • 1 reply
  • 308 views
  • 3 likes
  • 2 in conversation