Quartz | Level 8

## INTNX CALCULATION

`DATE_STATEMENT_START=INTNX("MONTH",DATE_STATEMENT,-1)+DAY(DATE_STATEMENT)-1;`

how to interpret this?

if DATE_STATEMENT is 20Nov2022

DATE_STATEMENT_START=20Oct2022+20-1

what if date_statement is 30Nov2022

what is intnx("MONTH",DATE_STATEMENT,-1) 30Oct2022 or 31Oct2022?

4 REPLIES 4
SAS Employee

## Re: INTNX CALCULATION

Hi.

Trying to draft an example per your notes.  Please try the following and if this is not what you are looking for, shed more light on your goal.  Thanks.

Data Test;
Date='20NOV2022'd;
Day=day(date);
DateNext=intnx('month',Date,-1,'same')+ Day-1;
format date datenext date9.;
run;

proc print data=test;
title "Values for Date, Day and DateNext";
run;

SAS Employee

## Re: INTNX CALCULATION

If you do not specify the fourth argument 'same' or 's' in intnx('month',Date,-1,'same'), the date will always be the first day of the month requested.  As you indicated, you can type 'e' for end, 'm' for middle, 's' for same, or 'b' for begin which is the default.

Quartz | Level 8

## Re: INTNX CALCULATION

so if I dont put b or e in intnx("MONTH",DATE_STATEMENT,-1)

It will always means same date no matter what date_statement is?

what if 31oct 2022, is it going to give 30sep2022

and 31mar2022 will give 28feb2022?

and 11oct2022 will give 11sep2022 as same date is assumed...

Super User

## Re: INTNX CALCULATION

As always, Maxim 1: Read the Documentation!

If no fourth argument is specified, the aligment defaults to "BEGINNING", so with a month interval you always get the first of the month. Adding the DAY value and subtracting 1 will result in the same day one month back, with the peculiar twist of what happens when you are at the end of a month with more days than the previous month. If you apply this on July 31, you get July 1 instead of June 30 (which would be the result of INTNX with a SAME alignment) .

Discussion stats
• 4 replies
• 454 views
• 3 likes
• 3 in conversation