BookmarkSubscribeRSS Feed
SiTheBSA
Calcite | Level 5

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!

1 REPLY 1
ballardw
Super User

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);
run;

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.

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 1 reply
  • 364 views
  • 0 likes
  • 2 in conversation