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

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

07:51:36:90299.8125
07:51:36:90299.8125
07:57:36:95999.80469
07:57:36:95999.80469
1 ACCEPTED SOLUTION

Accepted Solutions
Jim_G
Pyrite | Level 9

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

View solution in original post

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

gnrslasher37
Fluorite | Level 6
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.

##- Please type your reply above this line. Simple formatting, no
attachments. -##
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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; 
Jim_G
Pyrite | Level 9

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

Jim_G
Pyrite | Level 9

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

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!

SAS Enterprise Guide vs. SAS Studio

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.

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