BookmarkSubscribeRSS Feed
BCNAV
Quartz | Level 8

I have the following filter:

 

WHERE t1.flightdate >= intnx('Month',today(),-&months_back)

 

so if &months_back is 3, I will get data from all of June, July, and August of this year.....but it will also include September. I do not want September...I only want the last number of FULL months as identified with the macro variable &months_back. What filter can I add to get rid of the partial month dates?

3 REPLIES 3
Reeza
Super User
WHERE t1.flightdate >= intnx('Month',today(),-&months_back) and t1.flightdate < intnx('month', today(), 0, 'b');

Same idea, use INTNX() to get current months first day (interval = 0, aligment = b) and use BETWEEN or < for the date. 

 


@BCNAV wrote:

I have the following filter:

 

WHERE t1.flightdate >= intnx('Month',today(),-&months_back)

 

so if &months_back is 3, I will get data from all of June, July, and August of this year.....but it will also include September. I do not want September...I only want the last number of FULL months as identified with the macro variable &months_back. What filter can I add to get rid of the partial month dates?


 

ballardw
Super User

SAS supports structures like

 

Where value1 < value2 < value3

 

So add the other constraint

 

WHERE  somevalue > t1.flightdate >= intnx('Month',today(),-&months_back)

 

perhaps

 

where intx('month',today(),0,'B') > t1.flightdate >= intnx('Month',today(),-&months_back)

if you only want dates prior to the beginning of the current month.

 

 

novinosrin
Tourmaline | Level 20

where intnx('Month',today(),-3)<=date<=intnx('Month',today(),-1,'e');

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 1057 views
  • 0 likes
  • 4 in conversation