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

Hi, I currently have a table with a list of time intervals that aren't always continuous such as the first observation being 9:35:10- 9:35:20 and the second observation being  9:35:50- 9:36:00. I would like to create a new variable that adds seconds to each observation, for instance: 

 

Obs.        Time_interval              New_interval

1            9:35:10- 9:35:20         9:35:20- 9:35:30

2            9:35:50- 9:36:00         9:36:00- 9:36:10

3            9:36:10- 9:36:20         9:36:20- 9:36:30

 

 

I've tried using an INTNX function to create the new variable. The code runs but no there are no observations. Any suggestions would be greatly appreciated, thanks. Here is a sample of code I've tried:

 

data temp; set temp;
New_interval = intnx('ss',time_interval,10);
run;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Doing this the formal way:

 

data temp;
time_interval = "9:35:10- 9:35:20";
interval_start = input(scan(time_interval, 1, "-"), time8.);
interval_end = input(scan(time_interval, 2, "-"), time8.);
new_interval_start = intnx("second", interval_start, 10);
new_interval_end = intnx("second", interval_end, 10);
format interval_start interval_end new_interval_start new_interval_end time8.;
New_interval = catt(  
    put(new_interval_start, time8.), 
    "-",
    put(new_interval_end, time8.) );
run;
PG

View solution in original post

2 REPLIES 2
Reeza
Super User
INTNX will work on a date, datetime or time variable. My guess is that’s a character variable. If that’s the case, separate the times and then try INTNX again. Though time is stored in seconds so basic math and the ROUND/FLOOR/CEIL functions may be enough.
PGStats
Opal | Level 21

Doing this the formal way:

 

data temp;
time_interval = "9:35:10- 9:35:20";
interval_start = input(scan(time_interval, 1, "-"), time8.);
interval_end = input(scan(time_interval, 2, "-"), time8.);
new_interval_start = intnx("second", interval_start, 10);
new_interval_end = intnx("second", interval_end, 10);
format interval_start interval_end new_interval_start new_interval_end time8.;
New_interval = catt(  
    put(new_interval_start, time8.), 
    "-",
    put(new_interval_end, time8.) );
run;
PG