I have time variables in the format: mm:ss:ss (ex: 06:30:00) representing 06 minutes, 30 seconds, and 00 hundreths of a second.
Example listed below:
I was wondering if there was a way to assign a reference time value as 12 minutes (12:00:00) in descending order until 00:00:00 as in like a quarter for an NBA game. I'm sure I could do a do loop to achieve , but I was wondering if there was a global option to assign this just like the "yearcutoff= ####" global option does for datetime formats.
Any help in going about this or dealing with time values in SAS would be appreciated.
That's a simple division:
data have;
input clockstr $8.;
substr(clockstr,6,1) = '.';
game_clock = input('00:'!!clockstr,time11.2);
format game_clock mmss11.2;
keep game_clock;
cards;
11:42:00
10:10:00
03:43:00
;
run;
data want;
set have;
format prop_remain 5.3;
prop_remain = game_clock / '00:12:00't;
run;
proc print data=want noobs;
run;
Result:
prop_ game_clock remain 11:42.00 0.975 10:10.00 0.847 3:43.00 0.310
Can you please explain what do you mean by reference time value?
Can you post/display your expected results?
Doesn't input of your data, beeing converted to sas time variable and sorted - do what you want?
There is no such option for time, and your need is unclear. What should the output look like?
There should be a dot between seconds and hundredths, not a colon. Is this a string?
So basically, I want to convert the input in order to determine the proportion of how much time is remaining using the base value of 12:00:00. For example, converting the time input values into seconds, and converting the base value into seconds and dividing the input by the base.
I know how to do the math, but the formatting from the data set i was using was throwing me off, and I was confused on how to go about getting the output. I ended up reading up on the timew. informat that can read this and convert it to a value in seconds with the reference being 00:00:00 or 12 AM, which is similar to date informats in sas with days. From this comparison, I was wondering if there was a way to change this reference value with a global option.
That's a simple division:
data have;
input clockstr $8.;
substr(clockstr,6,1) = '.';
game_clock = input('00:'!!clockstr,time11.2);
format game_clock mmss11.2;
keep game_clock;
cards;
11:42:00
10:10:00
03:43:00
;
run;
data want;
set have;
format prop_remain 5.3;
prop_remain = game_clock / '00:12:00't;
run;
proc print data=want noobs;
run;
Result:
prop_ game_clock remain 11:42.00 0.975 10:10.00 0.847 3:43.00 0.310
Please supply some example data (convert your dataset to a data step with the macro provided in https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...), and examples for the expected results.
At first glance it appears that you also are dealing with periods
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.