Changing reference time for time variable in format (mm:ss:ss)

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Changing reference time for time variable in format (mm:ss:ss)

[ Edited ]

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:

 

 time.PNG

 

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.


Accepted Solutions
Solution
‎08-07-2017 11:44 AM
Super User
Posts: 7,854

Re: Changing reference time for time variable in format (mm:ss:ss)

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 
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Trusted Advisor
Posts: 1,584

Re: Changing reference time for time variable in format (mm:ss:ss)

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?

PROC Star
Posts: 1,760

Re: Changing reference time for time variable in format (mm:ss:ss)

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?

 

 

New Contributor
Posts: 3

Re: Changing reference time for time variable in format (mm:ss:ss)

Capture.PNG

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.

Solution
‎08-07-2017 11:44 AM
Super User
Posts: 7,854

Re: Changing reference time for time variable in format (mm:ss:ss)

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 
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 7,854

Re: Changing reference time for time variable in format (mm:ss:ss)

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 11,343

Re: Changing reference time for time variable in format (mm:ss:ss)

At first glance it appears that you also are dealing with periods

☑ This topic is solved.

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

Discussion stats
  • 6 replies
  • 117 views
  • 1 like
  • 5 in conversation