DATA Step, Macro, Functions and more

INTNX by 15 Minute

Accepted Solution Solved
Reply
Contributor
Posts: 33
Accepted Solution

INTNX by 15 Minute

Hi all,

One more question...  I have a time field that I want to increment to the next 15 minute interval.  So if the first obs is 00:36 I want 00:45, if 1:12 I want 1:15 etc.  Here's what I have so far, but it advances to the next hour, not 1/4 hour...

Min_Start = intnx('dthour',StartTime,.25, 'e');

format Min_Start HHMM.;


Accepted Solutions
Solution
‎03-12-2015 03:36 PM
Respected Advisor
Posts: 3,799

Re: INTNX by 15 Minute

I think, based on your description, you want the Start of the next 15 minute interval.

page;
data _null_;
  
do Starttime = datetime() by 15*60;
      I +
1;
     
if i eq 20 then stop;
      Min_Start = intnx(
'dtminute15',StartTime,1,'B');
      put (starttime min_start)(=datetime.);
      end;
  
run;

33         data _null_;
34            do Starttime = datetime() by 15*60;
35               I + 1;
36               if i eq 20 then stop;
37               Min_Start = intnx('dtminute15',StartTime,1,'B');
38               put (starttime min_start)(=datetime.);
39               end;
40            run;

Starttime=
12MAR15:12:34:38 Min_Start=12MAR15:12:45:00
Starttime=
12MAR15:12:49:38 Min_Start=12MAR15:13:00:00
Starttime=
12MAR15:13:04:38 Min_Start=12MAR15:13:15:00
Starttime=
12MAR15:13:19:38 Min_Start=12MAR15:13:30:00
Starttime=
12MAR15:13:34:38 Min_Start=12MAR15:13:45:00
Starttime=
12MAR15:13:49:38 Min_Start=12MAR15:14:00:00
Starttime=
12MAR15:14:04:38 Min_Start=12MAR15:14:15:00
Starttime=
12MAR15:14:19:38 Min_Start=12MAR15:14:30:00
Starttime=
12MAR15:14:34:38 Min_Start=12MAR15:14:45:00
Starttime=
12MAR15:14:49:38 Min_Start=12MAR15:15:00:00
Starttime=
12MAR15:15:04:38 Min_Start=12MAR15:15:15:00
Starttime=
12MAR15:15:19:38 Min_Start=12MAR15:15:30:00
Starttime=
12MAR15:15:34:38 Min_Start=12MAR15:15:45:00
Starttime=
12MAR15:15:49:38 Min_Start=12MAR15:16:00:00
Starttime=
12MAR15:16:04:38 Min_Start=12MAR15:16:15:00
Starttime=
12MAR15:16:19:38 Min_Start=12MAR15:16:30:00
Starttime=
12MAR15:16:34:38 Min_Start=12MAR15:16:45:00
Starttime=
12MAR15:16:49:38 Min_Start=12MAR15:17:00:00
Starttime=
12MAR15:17:04:38 Min_Start=12MAR15:17:15:00

View solution in original post


All Replies
Super Contributor
Super Contributor
Posts: 3,174

Re: INTNX by 15 Minute

Reviewing the SAS LANGUAGE documentation, have a look at INTNX and the DTMINUTEnn function.

Suggested browser search argument:  intnx function 15 minute interval site:sas.com


Scott Barry

SBBWorks, Inc.

Valued Guide
Posts: 860

Re: INTNX by 15 Minute

You could use proc format:

1 - 14 = 15

16 - 29 = 30 etc.

Solution
‎03-12-2015 03:36 PM
Respected Advisor
Posts: 3,799

Re: INTNX by 15 Minute

I think, based on your description, you want the Start of the next 15 minute interval.

page;
data _null_;
  
do Starttime = datetime() by 15*60;
      I +
1;
     
if i eq 20 then stop;
      Min_Start = intnx(
'dtminute15',StartTime,1,'B');
      put (starttime min_start)(=datetime.);
      end;
  
run;

33         data _null_;
34            do Starttime = datetime() by 15*60;
35               I + 1;
36               if i eq 20 then stop;
37               Min_Start = intnx('dtminute15',StartTime,1,'B');
38               put (starttime min_start)(=datetime.);
39               end;
40            run;

Starttime=
12MAR15:12:34:38 Min_Start=12MAR15:12:45:00
Starttime=
12MAR15:12:49:38 Min_Start=12MAR15:13:00:00
Starttime=
12MAR15:13:04:38 Min_Start=12MAR15:13:15:00
Starttime=
12MAR15:13:19:38 Min_Start=12MAR15:13:30:00
Starttime=
12MAR15:13:34:38 Min_Start=12MAR15:13:45:00
Starttime=
12MAR15:13:49:38 Min_Start=12MAR15:14:00:00
Starttime=
12MAR15:14:04:38 Min_Start=12MAR15:14:15:00
Starttime=
12MAR15:14:19:38 Min_Start=12MAR15:14:30:00
Starttime=
12MAR15:14:34:38 Min_Start=12MAR15:14:45:00
Starttime=
12MAR15:14:49:38 Min_Start=12MAR15:15:00:00
Starttime=
12MAR15:15:04:38 Min_Start=12MAR15:15:15:00
Starttime=
12MAR15:15:19:38 Min_Start=12MAR15:15:30:00
Starttime=
12MAR15:15:34:38 Min_Start=12MAR15:15:45:00
Starttime=
12MAR15:15:49:38 Min_Start=12MAR15:16:00:00
Starttime=
12MAR15:16:04:38 Min_Start=12MAR15:16:15:00
Starttime=
12MAR15:16:19:38 Min_Start=12MAR15:16:30:00
Starttime=
12MAR15:16:34:38 Min_Start=12MAR15:16:45:00
Starttime=
12MAR15:16:49:38 Min_Start=12MAR15:17:00:00
Starttime=
12MAR15:17:04:38 Min_Start=12MAR15:17:15:00
🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 508 views
  • 6 likes
  • 4 in conversation