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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 612 views
  • 0 likes
  • 3 in conversation