Help using Base SAS procedures

Convert numeric variable into SAS time variable

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

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
Trusted Advisor
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 --<-----

View solution in original post


All Replies
Solution
‎09-18-2014 09:14 AM
Trusted Advisor
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
Super User
Posts: 7,997

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;    

Trusted Advisor
Posts: 1,231

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.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 4504 views
  • 0 likes
  • 5 in conversation