turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- ODS and Base Reporting
- /
- Select the observation of every 1 minute

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

06-28-2007 02:17 PM

hello

I have a seri of data that contains time (hour : minute :second).

how can I have just the observation of every minute or every 15 minutes?

(hint:I want to do it in proc step)

I have a seri of data that contains time (hour : minute :second).

how can I have just the observation of every minute or every 15 minutes?

(hint:I want to do it in proc step)

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to deleted_user

06-29-2007 05:35 AM

The simplest way is to add a second column to your table that contains the time rounded to the interval you want to select. Here is some data to play with.

Data TIMES;

Attrib TIME Length = 5 Format = Time8.;

TIME = "01:04:15"t;

Output;

TIME = "01:04:38"t;

Output;

TIME = "01:04:55"t;

Output;

TIME = "01:05:23"t;

Output;

Run;

The data are in time order, and we will want the first record for each minute. So let's pass this data to another step and find the time rounded down to the nearest minute. There are many ways to do this, but I like the IntNx() function because it is so easy to work with. By telling IntNx() to use intervals of minute, we will round to the nearest minute. The directive "0" tells IntNx() that the minute shift is 0, that is the actual hour and minute values will be preserved. The final directive "b" instructs IntNx() to calculate the Beginning of the time interval.

Data TIMESTRAT;

Set TIMES;

TIMEROUND = IntNx( "Minute", TIME, 0, "b");

Format TIMEROUND Time8.;

Run;

Your data are in order of TIMEROUND TIME, so you can select the first value for each time rounded to the nearest minute by specifying the order with a BY statement, and then select the First.TIMEROUND record.

Now here comes the really good bit of IntNx(). If instead of specifying "Minute" you specify "Minute15" all times will round down to the nearest 15 minute interval in the hour.

Kind regards

David

Data TIMES;

Attrib TIME Length = 5 Format = Time8.;

TIME = "01:04:15"t;

Output;

TIME = "01:04:38"t;

Output;

TIME = "01:04:55"t;

Output;

TIME = "01:05:23"t;

Output;

Run;

The data are in time order, and we will want the first record for each minute. So let's pass this data to another step and find the time rounded down to the nearest minute. There are many ways to do this, but I like the IntNx() function because it is so easy to work with. By telling IntNx() to use intervals of minute, we will round to the nearest minute. The directive "0" tells IntNx() that the minute shift is 0, that is the actual hour and minute values will be preserved. The final directive "b" instructs IntNx() to calculate the Beginning of the time interval.

Data TIMESTRAT;

Set TIMES;

TIMEROUND = IntNx( "Minute", TIME, 0, "b");

Format TIMEROUND Time8.;

Run;

Your data are in order of TIMEROUND TIME, so you can select the first value for each time rounded to the nearest minute by specifying the order with a BY statement, and then select the First.TIMEROUND record.

Now here comes the really good bit of IntNx(). If instead of specifying "Minute" you specify "Minute15" all times will round down to the nearest 15 minute interval in the hour.

Kind regards

David