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

Scenario - I have a column with a due date.  If the month is 10,11 or 12, the due date is December 31st of three years from the due date.  If the month due is in months 1-9, it's due on the same day just 39 months from the due date.  I had two formulas provided to me but they aren't coming back right:

 

ifn(MONTH(t1.INACMSA) in (10,11,12), MDY(MONTH(t1.INACMSA),DAY(t1.INACMSA),YEAR(t1.INACMSA)+3),INTNX('MONTH',t1.INACMSA,39,'S'))

 

ifn(MONTH(t1.INACMSA) IN (10,11,12), MDY(12,31,YEAR(t1.INACMSA)+3),intnx('MONTH',t1.INACMSA,36,'S'))

1 ACCEPTED SOLUTION

Accepted Solutions
SuryaKiran
Meteorite | Level 14

Hello,

 

Do you really have date values or datetime values, if datetime then you need to extract the date part from it (datepart() function helps). 

 

Alternatively this should work:

data test ;
format INACMSA date date9.;
INACMSA='12JAN2017'd;
Date=ifn(MONTH(INACMSA) IN (10,11,12),INTNX('YEAR',INACMSA,3,'e'),INTNX('MONTH',INACMSA,39,'s'));
run;
Thanks,
Suryakiran

View solution in original post

4 REPLIES 4
SASKiwi
PROC Star

Looks like you are trying to do this in SQL - is that right?. If so then I'm not sure if the IFN function will work properly. Using a CASE statement is probably a better approach.

SuryaKiran
Meteorite | Level 14

Hello,

 

Do you really have date values or datetime values, if datetime then you need to extract the date part from it (datepart() function helps). 

 

Alternatively this should work:

data test ;
format INACMSA date date9.;
INACMSA='12JAN2017'd;
Date=ifn(MONTH(INACMSA) IN (10,11,12),INTNX('YEAR',INACMSA,3,'e'),INTNX('MONTH',INACMSA,39,'s'));
run;
Thanks,
Suryakiran
PaigeMiller
Diamond | Level 26

Instead of telling us "they aren't coming back right", show us (some of) the inputs and show us the outputs so we can know what is happening.

--
Paige Miller
Reeza
Super User

Not sure why you're using both MDY and INTNX, I'd probably recommend sticking with the same one. 

This works fine for me. 

 

data demo;
format date date9.;
input date date9.;
cards;
01Jan2014
03Jan2018
01Oct2014
31Oct2014
01Nov2015
30Nov2016
01Dec2016
31Dec2017
01Apr2018
30Sep2015
;;;;
run;

proc sql;
create table want as
select *, case when month(date) in (10, 11, 12) then intnx('year', date, 3, 'e')
               else intnx('month', date, 39, 's') end as due_date format=date9.
from demo;
quit;

@maliksmom2000 wrote:

Scenario - I have a column with a due date.  If the month is 10,11 or 12, the due date is December 31st of three years from the due date.  If the month due is in months 1-9, it's due on the same day just 39 months from the due date.  I had two formulas provided to me but they aren't coming back right:

 

ifn(MONTH(t1.INACMSA) in (10,11,12), MDY(MONTH(t1.INACMSA),DAY(t1.INACMSA),YEAR(t1.INACMSA)+3),INTNX('MONTH',t1.INACMSA,39,'S'))

 

ifn(MONTH(t1.INACMSA) IN (10,11,12), MDY(12,31,YEAR(t1.INACMSA)+3),intnx('MONTH',t1.INACMSA,36,'S'))


 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 756 views
  • 0 likes
  • 5 in conversation