BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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)
1 REPLY 1
deleted_user
Not applicable
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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1 reply
  • 811 views
  • 0 likes
  • 1 in conversation