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.80469 |
07:57:36:959 | 99.80469 |
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
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.
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;
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 |
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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: