## creating time interval

Solved
Occasional Contributor
Posts: 12

# creating time interval

i have the following data and need to create a interval of 5 minutes.

 07:51:36:902 99.8125 07:51:36:902 99.8125 07:57:36:959 99.8047 07:57:36:959 99.8047

Accepted Solutions
Solution
‎06-18-2016 02:41 AM
Frequent Contributor
Posts: 91

## Re: creating time interval

[ Edited ]

The following code will convert the first 2 obs time to 7:50:00  and the last 2 obs time to 7:55:00.

Then the data can be rolled up in 5 minute intervals.

Data;
input @1 stime time8.  @14 rate;
stime=floor(stime/300); stime =stime*300;   *** 300 is 5 minutes times 60 seconds per min;
format stime time8.;
cards;
07:51:36:902 99.8125
07:51:36:902 99.8125
07:57:36:959 99.80469
07:57:36:959 99.80469
proc print;
run;

Jim

All Replies
Super User
Posts: 7,720

## Re: creating time interval

Sorry, you would need to be more specific - post test data, in the form of a datastep - and what the output should look like.  For instance, why is there two records per group?  How many intervals do you need etc.  Test data and required output illustrate the point well.

Occasional Contributor
Posts: 12

## Re: creating time interval

I have a data set for timestamp and price, from which i have to create a 5
minute interval along with the price.

03:35:00:423 99.83
04:37:24:551 99.82
04:37:24:551 99.82
04:42:03:462 99.84
04:42:03:462 99.82
04:42:06:307 99.82
04:42:06:307 99.85
04:42:26:992 99.82
04:42:26:992 99.81
04:45:14:225 99.82
04:45:14:225 99.82
04:47:47:382 99.82
output should start from 03:35:00 to 03:40 and so on.

attachments. -##
Super User
Posts: 7,720

## Re: creating time interval

Let me try to explain my question again.  Take the first row of "test data" for want of a better word:

03:35:00:423 99.83

So how do you want to expand this, do you want just one additional row which is 5 minutes from that one, with the same price.  Or perhaps you want each minute between that and + 5 mins?   This for instance will output a row for each of the minutes:

```data want;
time="03:35"t; price=99.83;
do i=time to time+(5*60) by 60;
output;
end;
format time i time5.;
run; ```
Frequent Contributor
Posts: 91

## Re: creating time interval

The following code produces a new row with a 5 min time interval for each price.

data; input @1 time time8. @ 14 price;

intval=floor(time/300);

intval=intval*300;

format intval time time8.;

cards;

03:35:00:423 99.83

04:37:24:551 99.82

04:37:24:551 99.82

04:42:03:462 99.84

04:42:03:462 99.82

04:42:06:307 99.82

04:42:06:307 99.85

04:42:26:992 99.82

04:42:26:992 99.81

04:45:14:225 99.82

04:45:14:225 99.82

04:47:47:382 99.82

proc print; run;

 Obs time price intval 1 3:35:00 99.83 3:35:00 2 4:37:24 99.82 4:35:00 3 4:37:24 99.82 4:35:00 4 4:42:03 99.84 4:40:00 5 4:42:03 99.82 4:40:00 6 4:42:06 99.82 4:40:00 7 4:42:06 99.85 4:40:00 8 4:42:26 99.82 4:40:00 9 4:42:26 99.81 4:40:00 10 4:45:14 99.82 4:45:00 11 4:45:14 99.82 4:45:00 12 4:47:47 99.82 4:45:00
Solution
‎06-18-2016 02:41 AM
Frequent Contributor
Posts: 91

## Re: creating time interval

[ Edited ]

The following code will convert the first 2 obs time to 7:50:00  and the last 2 obs time to 7:55:00.

Then the data can be rolled up in 5 minute intervals.

Data;
input @1 stime time8.  @14 rate;
stime=floor(stime/300); stime =stime*300;   *** 300 is 5 minutes times 60 seconds per min;
format stime time8.;
cards;
07:51:36:902 99.8125
07:51:36:902 99.8125
07:57:36:959 99.80469
07:57:36:959 99.80469
proc print;
run;

Jim

☑ This topic is solved.