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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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 

View solution in original post

6 REPLIES 6
Shmuel
Garnet | Level 18

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?

ChrisNZ
Tourmaline | Level 20

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?

 

 

bgonth1
Fluorite | Level 6

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.

Kurt_Bremser
Super User

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 
ballardw
Super User

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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