BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Shradha1
Obsidian | Level 7

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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.;

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

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.;
PeterClemmensen
Tourmaline | Level 20

Simply replace "30APR2021"d with today() for the dynamic transformation.

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