Unsure how to code a better macro for the requirements?

Occasional Learner
Posts: 1

Unsure how to code a better macro for the requirements?

Hello all,


I have a SAS program that i run monthly where i have to pull data from dozens of files that are also updated monthly. The issue i have is with the date macros in the program. They work but i would like to make things more efficient for someone that is going to be taking on the process. My question is, is there a way to have a macro use the first day of the prior month to the time i run the report? Also, have one use the last day of the prior month to when i am running the report? Currently, i open the program and update a few areas with the next month in line prior to running the reports. Because the person who is going to take on this job does not understand coding, i would like to make it so they only have to run the program for now as they learn. I am also not en expert but know enough to be dangerous. below is an example of what i am talking about.


Example macro:


%let begin_dt = '01Sep2015'd;

%let end_dt = '31sep2016'd;


When November rolls around i will update a few things like this to show the previous month/day combinations.


Example for November:


%let begin_dt = '01Oct2015'd;

%let end_dt = '31Oct2016'd;


I would prefer to set things up so that this does not have to be updated each month and rather program so that it will use the correct inforation on its own when the program is run.


Does anyone have an idea of how to set this up? I have tried a few things but have not successfully made this work.


Thank you all!

Super User
Posts: 13,583

Re: Unsure how to code a better macro for the requirements?

If the program involved always is run to refer to the previous month from the date of execution then you could stick this code inside the macro


data _null_;
   sdate= intnx('month',today(),-1,'B');
   edate= intnx('month',today(),-1,'E');
   call symputx('begin_dt',sdate);
   call symputx('end_dt',edate);

Note that the values will be the numeric version of the SAS date value which should match for your uses UNLESS you are printing those directly in titles or such.


Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation