01-03-2014 02:24 PM
I have reports that are run daily, however I do not want to run it if the office was close on the previous day. I have compiled a dataset that has 1 record for every day of the year with a binary for whether the office is open or not.
1. How can I check this at the beginning of a program versus "Yesterday"
2. How can I skip a whole lot of code, send an email to myself saying.. the program ran but no reports were necessary and then terminate the sas session. I am running this on batch in a windows nt environment on sas 9.1
01-03-2014 02:56 PM
Ok so the way that I understand this is that you are going to have a dataset which has dates and a flag 1/0 if the office was open and therefore the program should run.
So this is just an example of what the dates would look like if they were read in for explanation purposes.
input date open ;
informat date mmddyy10. open best2.;
format date mmddyy10.;
proc sql noprint;
into open_list separated by '*'
where open =1;
%let open_cntlist = &sqlobs;
%let print_date = %sysfunc(today(), MMDDYY10.);
%let yesterday = %sysfunc(intnx(day, %sysfunc(InputN(&print_date,MMDDYY10.)),-1),MMDDYY10.);
%do I = 1 %to &open_cntlist.;
%Let opendt = %scan(&open_list.,&I.,'*');
%if &opendt=&yesterday %then %do;
/*Insert code to run report*/
/*Insert email code for report*/
/*insert email code for not open yesterday*/
The report will be skipped and only an email saying that the office wasn't open will be sent if yesterday was not a day that was open.
01-03-2014 11:27 PM
As I understand your requirement you're trying to mimic what scheduling software like LSF normally would do for you. You will need some wrapper code which checks if programs should be run or not - and then do "stuff" accordingly.
If you want to take things a bit further you probably would also maintain a control table where you log job execution (started, finished, finished with errors and so on). In the wrapper you could also check the return codes of the batch submitted jobs and then send an email notification if a job fell over - or an email once all jobs finished executing. You might also consider to use a control table to only batch submit a job once a day - so when something falls over then you fix the job(s) and restart the scheduler which then only runs jobs not already successfully run on the day. ...but in the end: that's scheduling software functionality so when the requirements increase then using such software is may-be the better option than hand-coding.
Below a code example which might serve you as starting point.
attrib Date format=date9. Run_flg length=$1;
do date=today()-1 to today()+1;
if date=today() then run_flg='1';
length path $300 prgm $40;
infile datalines truncover dlm='|';
input path prgm;
set &calendar (where=(date=today()));
%if &run_flg ne 1 %then
%put SEND EMAIL THAT NOT RUNNING;
%put SEND EMAIL THAT PROGRAMS BEING EXECUTED;
retain cmd1 '"C:\Program Files\SASHome\SASFoundation\9.4\sas.exe" -CONFIG "C:\Program Files\SASHome\SASFoundation\9.4\nls\en\sasv9.cfg" nosplash noicon';
length cmd2 cmd3 cmd4 $1000 cmd $4000;
cmd=strip(cmd1)||' '||strip(cmd2)||' '||strip(cmd3)||' '||strip(cmd4)||' ';
01-04-2014 10:29 AM
To conditionally run code you normally need to use a macro. If you are not already using a macro in your program you can just wrap your existing program into a macro.
Once you are running a macro you can use %DO/%END blocks to control which parts run.
I would structure the program in this order:
- Test if reports need to run and set macro variable.
- If report need to run then run it.
- Produce email using the same macro variable to conditionally generate the content depending on whether reports were run or not.