BookmarkSubscribeRSS Feed
aknight1
Obsidian | Level 7

Hi all,

 

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,

Antony

 

%macro mirsleep(sleepstart ='05:00:00't

,sleepend ='06:30:00't

,sleepday = 1

);

%let sleepvar = %substr(&sleepend,2,8);

data _null_;

day=weekday(today());

sleeptime=&sleepend.-time();

start_time=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;

 

%mend;

 

%mirsleep;

5 REPLIES 5
Kurt_Bremser
Super User

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.

aknight1
Obsidian | Level 7

Hi Kurt,

 

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?

 

Regards,

Antony

LinusH
Tourmaline | Level 20

B.

But be aware of Time Zone settings if the mainframe server multiple countries/tome zones.

Data never sleeps
Kurt_Bremser
Super User

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)

aknight1
Obsidian | Level 7

Hi Kurt,

 

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.

 

Regards,

Antony

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 5 replies
  • 839 views
  • 1 like
  • 3 in conversation