- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
As in your previous question, we need to see the PROC CONTENTS results for this variable.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you! It worked 😁
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I think it should be the YYMMDDN8. format, otherwise the date would come out as YY-MM-DD.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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.