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.

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