SAS INTNX function ( add days, months, years, etc )

This post was kindly contributed by AFHood Analytics Group - Blogs » SAS - go there to comment and to read the full post.

The INTNX function increments dates, times, or datetimes by specific or custom intervals.

Here is the basic syntax for INTNX:

INTNX(interval[multiple.shift-index], start, increment[, alignment])

The interval can be a set value like – DAY, WEEK, DTWEEK, YEAR, etc. You can also specify a custom interval. We will post more on that later.

The multiple is optional and used as such. If you want the interval to be a 2 year period or biennial, you could use YEAR2. It is the same with weeks. If you were calculating 2 week pay periods and you wanted to increment by such, you would declare the interval to be WEEK2.

The shift-index lets you define a starting point within the interval. An example would be to start the week on Monday.  The interval designation should be WEEK1.2 .

The start is your date, time, or datetime at which you want to begin the increment.

Increment is a positive or negative integer representing the number of interval shifts that should be made from the start.

Alignment is an excellent tool. It allows you to designate at which point SAS should return within an interval. You can specify:

B – beginning

M – middle

E – end

S – same

The default for alignment is beginning.

This post was kindly contributed by AFHood Analytics Group - Blogs » SAS - go there to comment and to read the full post.