The SAS Output Delivery System and reporting techniques

Select the observation of every 1 minute

Reply
N/A
Posts: 0

Select the observation of every 1 minute

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)
N/A
Posts: 0

Re: Select the observation of every 1 minute

Posted in reply to deleted_user
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
Ask a Question
Discussion stats
  • 1 reply
  • 215 views
  • 0 likes
  • 1 in conversation