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
and what is the answer?
what if date_statement is 30Nov2022
what is intnx("MONTH",DATE_STATEMENT,-1) 30Oct2022 or 31Oct2022?
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;
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.
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...
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) .
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.