07-10-2017 06:06 AM
SAS9.1 on MVS with OPC Scheduler.
I have a problem in my program which I think is coming from the TODAY() function in combination with OPC scheduler on MVS.
We have an OPC Application which is scheduled for the 1st day of every month. It contains a Job that is scheduled to start at 05:00. In effect this means that the Job always starts on the NEXT day, because the daily OPC schedule is created at 06:00.
In my Job I have a macro which will force SAS to sleep between 05:00 and 06:30 on Sundays, to avoid connecting to a Server which is down at that time. I did not write this macro, but I believe it works correctly (I have included it below).
In months of April 2017 and July 2017 the Job fails. These months both start with a Saturday. In the Logs I see that the PUT statement has not executed. So the code has decided that the date/time is NOT a Sunday between 05:00 and 06:30. However, the Job Logs show that the Jobs are running at these times (02.04.2017 05:00:08, and 02.07.2017 05:33:18, respectively). In both of these Jobs, the PUT statement and the SLEEP did not execute.
Currently I am thinking that the problem is coming from the TODAY() function. Where does the TODAY() function get its information from? If the OPCE schedule is running for Day A, but within that schedule the Job is actually running on Day B, what will be value returned by the SAS TODAY() function? (A or B?) Does anybody know this? (Impossible for me to test this at the moment).
Thanks for any info,
%macro mirsleep(sleepstart ='05:00:00't
,sleepday = 1
%let sleepvar = %substr(&sleepend,2,8);
if day=&sleepday and
((start_time ge &sleepstart.) and (start_time le &sleepend.))
put "Info: SAS going to sleep till &sleepvar. by "
07-10-2017 06:48 AM
Do not use functions like today() in a production job that is run by a scheduler. Instead have the execution date delivered by the scheduler as a parameter, and use that in the program.
Otherwise you'll never be able to re-run a job correctly on a later day.
07-10-2017 07:01 AM
Thanks for your reply.
In this case, the use of the TODAY and TIME functions is to determine explicitly what is the CURRENT date and time (not what is the scheduled execution date and time) so that the job can avoid connection to a server during its downtime. If we used the execution date passed as a parameter from the scheduler, I think we would not be certain to be checking the CURRENT date?
07-10-2017 07:28 AM
But be aware of Time Zone settings if the mainframe server multiple countries/tome zones.
07-10-2017 07:30 AM
I see. For debugging purposes, I would slightly restructure the data step code:
data _null_; start_day = today(); start_time = time(); put start_day= date9.; put start_time= time8.; day = weekday(start_day); sleeptime = &sleepend. - start_time; if day = &sleepday and start_time ge &sleepstart. and start_time le &sleepend. then do; put "Info: SAS going to sleep till &sleepvar. by " sleeptime=; time_slept = sleep(sleeptime,1); end; run;
Now you will always have the current date and time as SAS sees it in the log. You might have a situation where the scheduler and SAS operate in different timezones (local vs. GMT, for instance)
07-10-2017 07:47 AM
Thanks again. Of course I've made similar changes to your suggestions in my testing, and I just get the results that I expect.
To get useful info I'd need to implement this in the environment where the Scheduler can run for Day A but delay a job from running until Day B. Such a test will involve a lot of time & hassle in our environment, so I was hoping if somebody already knows that the TODAY() function would return Day A in that situation.
Thanks for your time.