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

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

tijanagilic_0-1704556335883.png

And i want to be able to put macro, like this in any table.

 

tijanagilic_1-1704556389245.png

 

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

OK - so you've got just a number and not a SAS Date value in your data:

Patrick_0-1704560028642.png

 

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;

Patrick_1-1704560113674.png

 

 



 

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

As in your previous question, we need to see the PROC CONTENTS results for this variable.

--
Paige Miller
Patrick
Opal | Level 21

OK - so you've got just a number and not a SAS Date value in your data:

Patrick_0-1704560028642.png

 

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;

Patrick_1-1704560113674.png

 

 



 

tijanagilic
Obsidian | Level 7

Thank you! It worked 😁

Tom
Super User Tom
Super User

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.)

 

Tom
Super User Tom
Super User

@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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 849 views
  • 3 likes
  • 5 in conversation