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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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
  • 6 replies
  • 898 views
  • 1 like
  • 5 in conversation