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

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.;

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

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

3 REPLIES 3
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10

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.

Steelers_In_DC
Barite | Level 11

You could use proc format:

1 - 14 = 15

16 - 29 = 30 etc.

data_null__
Jade | Level 19

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

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!

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
  • 3 replies
  • 2583 views
  • 6 likes
  • 4 in conversation