I want to create two macro variables, one for start date and one for end date, both in date9. format. the start date will be 60 days before today's date and end date will be 7 days before today's date. Suppose, today is 30APR2021, then I can create macros like this:
%let start_date= 01MAR2021;
%let end_date= 23APR2021;
But the problem with this is that I have to run this code on a daily basis which means that each day I will have to change the values of the macro variables. So I want to automatize it in a way that if I am running the code on 01MAY2021 (T) suppose, then the macros will automatically take Start date= 02MAR2021 (T-60) and End date = 24APR2021 (T-7).
Is there any way to automatize these macros to become dynamic and to take values based on the current date?
Try this
data _null_;
call symputx('start_date', put(intnx('day', "30APR2021"d, -60, 's'), date9.));
call symputx('end_date' , put(intnx('day', "30APR2021"d, -7, 's'), date9.));
run;
%put &start_date.;
%put &end_date.;
Try this
data _null_;
call symputx('start_date', put(intnx('day', "30APR2021"d, -60, 's'), date9.));
call symputx('end_date' , put(intnx('day', "30APR2021"d, -7, 's'), date9.));
run;
%put &start_date.;
%put &end_date.;
Simply replace "30APR2021"d with today() for the dynamic transformation.
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!
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.