Hello,
I am using Enterprise Guide, and I have many tables that contain a column that contains a date that is in the form, e.g. 20231231 or 20231031. The column is numeric type and I need a macro variable, which when I put it in the filter, will eject the data for the last day of the previous month.
Data in the columns
And i want to be able to put macro, like this in any table.
Thanks in advance!
OK - so you've got just a number and not a SAS Date value in your data:
And you want a macro variable with such a number for the last day of the previous month based on the date when you are running the code.
%let previous_month=%sysfunc(intnx(month,%sysfunc(today()),-1,e),yymmddn8.);
%put &=previous_month;
As in your previous question, we need to see the PROC CONTENTS results for this variable.
OK - so you've got just a number and not a SAS Date value in your data:
And you want a macro variable with such a number for the last day of the previous month based on the date when you are running the code.
%let previous_month=%sysfunc(intnx(month,%sysfunc(today()),-1,e),yymmddn8.);
%put &=previous_month;
Thank you! It worked 😁
No need to define a macro or even create a macro variable.
Instead you can just call a macro function.
Put this code into the value of your filter:
%sysfunc(intnx(month,%sysfunc(date()),-1,e),yymmddN8.)
I think it should be the YYMMDDN8. format, otherwise the date would come out as YY-MM-DD.
@Kurt_Bremser wrote:
I think it should be the YYMMDDN8. format, otherwise the date would come out as YY-MM-DD.
Thanks. Updated the answer.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.