BookmarkSubscribeRSS Feed
Son_Of_Krypton
Fluorite | Level 6

Currently i am fetching data based on below date filter manually.

 

Previous_Date>20191201 and Current_Date<20201201 

 

I want take above date dynamically using macro.

 

Then next year it should be Previous_Date>20201201 and Current_Date<20211201 and it should go on for every year

3 REPLIES 3
Kurt_Bremser
Super User

I SERIOUSLY doubt that your code works, unless you have "dates" stored in a most unusable fashion. December 1st, 2019 must be written as "01dec2019"d to be a SAS date value.

 

Having said that, here's code that shows how to derive your dates from a given year:

%let year=2020;

data _null_;
call symputx("prevcut",mdy(12,1,&year. - 1));
call symputx("currcut",mdy(12,1,&year.));
run;

which you can then use to compare with dates stored in a dataset:

Previous_Date > &prevcut. and Current_Date < &currcut.
Son_Of_Krypton
Fluorite | Level 6
I don't want to use %let statement it should pick up the year from dataset and should increase by year when it will start running for next year
Kurt_Bremser
Super User

@Son_Of_Krypton wrote:
I don't want to use %let statement it should pick up the year from dataset and should increase by year when it will start running for next year

Is the year in a variable within the dataset, or is it part of the dataset name? If the latter, are those dataset names structured consistently, and how?

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
  • 867 views
  • 0 likes
  • 2 in conversation