I have a data set with multiple time variables.
Time Variables: GCO Time, AVB Time, Event Time, etc.
Times: 0800 1200 0300 etc.
When I input my data set it inputs those variables as character functions. However, I am going to need to add and subtract the times, so character format will not work. I have tried to change the format when the dataset inputs to a time format, however I recieve an error when I do it that way. This should be an easy fix, just cant seem to find the solution.
I am using SAS Enterprise Guide 5.1
You can't format a column as time format if its character as time and date are numeric. To do it your way you would need to create a new numeric variable with the time5. format and input() the data into that:
data want; set have; new_time=input(cats(char_time,"00"),hhmmss.); format new_time time5.; run;
Although I would first check how your getting the data in, is it some sort of import? If so is it from Excel maybe?
You can't format a column as time format if its character as time and date are numeric. To do it your way you would need to create a new numeric variable with the time5. format and input() the data into that:
data want; set have; new_time=input(cats(char_time,"00"),hhmmss.); format new_time time5.; run;
Although I would first check how your getting the data in, is it some sort of import? If so is it from Excel maybe?
Or even simpler:
new_time=input(char_time,hhmmss4.);
input(cats(char_time,"00"),hhmmss.) worked perfectly!
Thank you!
Hi, why did you use "00" and why wont it work with any other time format such as HHMM.? Thanks!
Please don't re-open old questions with new questions. I add 00 so that the string is the correct format for the format I am using. In the format the length is default 6, so 2 char for hour, and for min, and for sec. As the data only has 4, 2 for hour, 2 for min, then I added 2 for second. See @PaigeMiller's response on how to shorten the length so that adding seconds is not needed.
data have;
input GCO$ AVB$ Event$;
datalines;
0800 1200 0300
;
data want;
set have;
num_GCO = input(GCO,hhmmss4.);
num_AVB = input(AVB,hhmmss4.);
num_Event = input(Event,hhmmss4.);
format num: time.;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.