BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mealie
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
jakarman
Barite | Level 11

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

5 REPLIES 5
jakarman
Barite | Level 11

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 --<-----
mealie
Calcite | Level 5

Thank you, this works 🙂

DATA new;

    Set old;

    time_new= time_old * 3600;

    FORMAT time_new hhmm.;

Run;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

your_new_time_variable=hms(your_number_variable,0,0);

Mwechtal
Calcite | Level 5

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;    

stat_sas
Ammonite | Level 13

data have;

input t;

time=t*3600;

format time time5.;

datalines;

12

14

15

;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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