SAS Enterprise Guide

Desktop productivity for business analysts and programmers
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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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