Solved
New Contributor
Posts: 2

# Convert numeric variable into SAS time variable

Hi all,

this is probably an easy one but today my brain is not working.

I have the numeric variable time with e.g. the values 12, 15, 18, ... . Those values should be converted to a SAS time format representing the clock time e.g. 12:00, 15:00, 18:00.

Could you help me to figure out the code?

Thanks a lot

Mealie

Accepted Solutions
Solution
‎09-18-2014 09:14 AM
Posts: 3,215

## Re: Convert numeric variable into SAS time variable

get those brains on, I hope there is an on/off switch....
Time and dates are numerics  they are nice presented by SAS formats.  The only thing I could make up is you are having some number that is in hours.
60 minutes in an hour with 60 seconds and you get the time in seconds. That is the SAS standard of time measurement.

---->-- ja karman --<-----

All Replies
Solution
‎09-18-2014 09:14 AM
Posts: 3,215

## Re: Convert numeric variable into SAS time variable

get those brains on, I hope there is an on/off switch....
Time and dates are numerics  they are nice presented by SAS formats.  The only thing I could make up is you are having some number that is in hours.
60 minutes in an hour with 60 seconds and you get the time in seconds. That is the SAS standard of time measurement.

---->-- ja karman --<-----
New Contributor
Posts: 2

## Re: Convert numeric variable into SAS time variable

Thank you, this works :-)

DATA new;

Set old;

time_new= time_old * 3600;

FORMAT time_new hhmm.;

Run;

Super User
Posts: 9,599

## Re: Convert numeric variable into SAS time variable

Hi,

your_new_time_variable=hms(your_number_variable,0,0);

Occasional Contributor
Posts: 11

## Re: Convert numeric variable into SAS time variable

The SAS function HMS looks like what you need. The 3 arguments are hour, minute, and second. Just use 0 for minute and second. You may need to format the resulting number in your favorite time format.

data _null_;

ref = hms(13, 0, 0);

put ref /

ref time.;

run;

Posts: 1,270

## Re: Convert numeric variable into SAS time variable

data have;

input t;

time=t*3600;

format time time5.;

datalines;

12

14

15

;

🔒 This topic is solved and locked.