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?

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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