06-08-2017 04:15 PM
Using SAS 9.4 on our LINUX box and run daily CRON job which kicks off 150 SAS reports. I have to add a trigger to my CRON job so that the SAS reports will not kick off unless all these values are true in the Load_Status table. [If name = process_name and Status = Ready and date = today].
I can run a PROC SQL; to get the results but do not know how to put it into a macro do loop so that it repeats until the results resolve to true.
We have other triggers for other datasets which I understand because they are just looking for a dataset name which includes a date. This one needs to look for specific values inside a table.
06-08-2017 04:33 PM
If I understand you right, you want to schedule this job to run at a particular time (let's say 6:00 AM), but sometimes the dependencies won't be ready yet, and you don't want the SAS processing to happen until all data is in place. So...you want to poll the data (Load_Status) periodically until those conditions are true. You don't want to poll constantly over and over, but probably wait 1 or 2 minutes between checks, right?
You want to be careful not to create an infinite loop, so I'd advise adding another condition to check (like...it's LUNCHTIME) and give up for the day.
Check out this tip from @MMMMIIIIKKKKEEEE about the WAKEUP function. That might be a useful way to tell your program to wait for a bit. SAS does have a lesser used (but still useful) control flow mechanism with GO TO and "label" constructs in a DATA step. You could use such a construct in DATA step to read the Load_Status table, if not ready then GO TO waitforit:, use WAKEUP to delay before checking again, etc.
Sorry it's not a complete solution. In the time I'm typing this someone else is probably composing something that is a perfect approach and ready to go....but at least I've plugged Mike's post.
P.S. Another approach might be to use a shell script in the cron job, let it run a SAS program to do the checking, write out an environment variable with the result, and include the looping/break logic in the shell script instead of in the SAS program.
06-08-2017 04:46 PM
06-09-2017 05:05 AM
Once you have reached this state of job complexity (150 reports is considerable), you should start building your own job infrastructure.
Since using a dedicated SAS server (and not just a SAS workstation), and the number of reports point to a certain size of your organisation, I think that there is an organisation-wide scheduling system already in place. I strongly recommend to attach the data warehouse to that.
For this I suggest:
1) have an individual program for your reports (or a group of reports created from the same source(s))
2) all those programs must be able to run in batch, with the same prerequisites (think Linux environment variables used for program control)
3) create a bash script that performs a single batch run, which handles the creation of individual job logs, and returns exit codes properly; you can find a blueprint for this in the Lev1/SASApp/BatchServer directory (you might even be able to customize this to your needs with the _usermods files)
Now you can start to build the connection from the organisation scheduler to the SAS box, and have your jobs run when the main scheduler has successfully run the jobs that create your inputs.
As an intermediate solution, you could also write a master script that repeatedly calls the script from 3) for all your jobs, checks for return codes, and handles the sequence as necessary.
While this means a lot of work to set up, once you have the infrastructure in place, adding new jobs and dependencies is a "piece of cake".