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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.