Hello, I am new to SAS shell scripting. I've been tasked to run a piece of code and a macro on the 5th, 6th, and 7th day of each month. If it is the 5th, 6th, or 7th, the code should be run at 9AM. I have figured out what I think is an easy way for running the script on the correct dates. I am less sure about running it at the correct time (9AM). I've thought of doing this the same way as the date, but I'm worried that this method might not be resource efficient.
%let currentDT = %sysfunc(datetime());
%let currentDate = %sysfunc(today());
%macro check_for_errors(pgm_name);
...
%mend check_for_errors;
data _null_;
DOM = "¤tDate" - intnx('month', "¤tDate", 0)+1;
if DOM in (5,6,7) then do;
call execute ('%include "/script_directory/script_name.sas";');
call execute ('%check_for_errors("script_name.sas");');
end;
else;
run;
DOM = "¤tDate" - intnx('month', "¤tDate", 0)+1;
If you put quotes around your macro variables as you showed, I think you get an error because your code tries to subtract a missing numeric (that's what you will get from INTNX as you have written it) from a character string "¤tdate". Can't subtract anything from a character string.
I think this should use the DAY function.
DOM = day(¤tdate);
and later
if DOM in (5,6,7) and hour(¤tDT)=9 then do;
As far as "I'm worried that this method might not be resource efficient", why do you think that? What is your concern?
UPDATE: I agree with @SASKiwi 's suggestion to use built in scheduling tools rather than write this yourself.
and hour(¤tDT)=9 then do;
Wouldn't this make the program run as many times as it is... I'm not sure how to word it. If SAS EG "reads" this program multiple times between 9 and 10, wouldn't it run it multiple times?
Its a lot easier to run SAS using a scheduling tool rather than programming your own scheduling in SAS itself. Your SAS appears to run on Unix which provides cron for scheduling. Alternatively you can use SAS Management Console which provides a point-and-click interface to scheduling, amongst other capabilities.
@calger wrote:
We use SAS Enterprise Guide and I was told by my sadistic supervisor that it needs to coded.
Not sadistic. Only an idiot.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.