BookmarkSubscribeRSS Feed
calger
Fluorite | Level 6

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 = "&currentDate" - intnx('month', "&currentDate", 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;

6 REPLIES 6
PaigeMiller
Diamond | Level 26
DOM = "&currentDate" - intnx('month', "&currentDate", 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 "&currentdate". Can't subtract anything from a character string.

 

I think this should use the DAY function.

 

DOM = day(&currentdate);

 

and later

 

if DOM in (5,6,7) and hour(&currentDT)=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.

--
Paige Miller
calger
Fluorite | Level 6
I cannot do that, I was told to code it.
calger
Fluorite | Level 6

and hour(&currentDT)=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?

SASKiwi
PROC Star

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
Fluorite | Level 6
We use SAS Enterprise Guide and I was told by my sadistic supervisor that it needs to coded.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 6 replies
  • 1774 views
  • 3 likes
  • 4 in conversation