Search code examples
sassas-macro

Date calculations in Advanced Expression builder in SAS Enterprise Guide 7.1


I am doing calculations with dates SAS EG 7.1. I need to calculate the last day of the month two months from the date in another column. The dates vary row buy row so needs to be dynamic and update the year and get the correct last day of month.

Let's use today's date 12th December 2023 as an example. I want to be able to use a calc to get this to 28/02/2024.

The only function I can see that allows interval adding to dates is INTX but this only allows one period (day, month year etc) at a time. This leads to the second problem - as far as i can tell, there is no way to store the date in a variable inside of the Expression Builder so I am unable to call INTX more than once.


Solution

  • For Date Calculations i always use the INTNX Function.

    Usage in QueryBuilder QueryBuilder Image

    Usage data steps

        intnx(month, &yourDateVar., 2, e)
    

    Usage in a macro

        %sysfunc(intnx(month, &yourDateVar., 2, e))
    

    See sas documentation for INTNX Function for more details