Four ways to schedule SAS tasks

57

What do you do all day long? I spend my time speaking with customers about what’s new in SAS 9.4, answering technical questions, and showing new users what they can do in SAS. You might spend your time on SAS data management tasks such as bringing in data and joining tables together, SAS analytic tasks such as building a model, or finally, SAS reporting tasks to share your insight throughout the organization.

The question is: how can we speed this up for you and give you some of that valuable time back? The answer is: by making all of these SAS processes repeatable.

The best way to make them repeatable is to take advantage of the SAS functionality for scheduling. Analysts have several options for scheduling their work to be run on a regular basis, whether it’s daily, weekly, monthly or otherwise. The options range all the way from writing SAS code, to a point-and-click GUI, to tools for IT Administrators.

1. Scheduling SAS code in batch

If you are a SAS coder, like me, you may have a lot of *.sas files on your computer. You can still schedule these pieces of code to run by setting up a batch process.

First, you will want to create a *.bat file that can be recognized by your operating system. You will need to know where SAS is installed on your local machine. You will also need to decide where to save your output (the *.lst file) and your log file (the *.log file). It is also possible to run multiple pieces of SAS code in the same *.bat file. These jobs will run consecutively. You can create the *.bat files in a text editor, like this:

Then, you will want to use your operating system (OS) scheduler to schedule the job. On my Windows 7 laptop, I use the “Task Scheduler” and select “Create Task”.

The minimum changes required are under “Triggers” and “Actions”. Under “Triggers” select “New” and make your selections appropriately. Select OK when done. Here are my selections.

Then under “Actions”, select “New” and make your selections appropriately. Select OK when done. Here are my selections.

Click OK and you are good to go! After the task has run, you can see if it was successful by checking out the “Task Status” under the Task Scheduler.

For more information, Examples of Batch Processing under Windows talks about scheduling in batch mode using your operating system.

2. Scheduling process flows or projects in SAS Enterprise Guide

Do you prefer point-and-click? SAS Enterprise Guide makes it easy to schedule your process flows or entire projects using your Windows operating system. SAS Enterprise Guide includes a built-in scheduler.

Chris Hemedinger has written on the topic, so I’ll let the expert speak for me. In his blog post Doing more with SAS Enterprise Guide automation, Chris writes about going beyond basic scheduling and taking advantage of the Enterprise Guide scheduler. He also wrote a paper on the topic: Not Just for Scheduling: Doing More with SAS® Enterprise Guide® Automation.

If you are looking for basic scheduling of Enterprise Guide process flows and projects, simply click on “File” -> “Schedule Project” or click on “Schedule” above the workspace and then select “Project” or “Process Flow”. This will open up your operating system scheduler. In my case it is using Windows Task Scheduler again. Follow the prompts from there. They are similar to what I had in example # 1 above. This is discussed in greater detail in the free chapter available for The Little SAS Book for Enterprise Guide 4.2. More information is also available in the HELP menu of SAS Enterprise Guide, under “Automating Projects”.

3. Scheduling jobs with SAS Management Console

SAS administrator? The Schedule Manager plug-in in SAS Management Console takes advantage of your operating system scheduling server. The Scheduler Manager can be used to schedule user-written SAS code or jobs that were created in SAS Data Integration Studio, SAS Marketing Automation, SAS Marketing Optimization and SAS Web Report Studio. Additionally, those batch tasks we talked about in #1? Yep, you can schedule them here, too. You are also able to create flows, which can consist of multiple SAS jobs. Most typically, the criteria for triggering the job here is Date/Time.

For more information, please see Operating System Scheduling under SAS Management Console documentation.

4. Scheduling with the Platform Suite for SAS

Need something with a little more oomph? Sometimes you need more advanced scheduling capabilities, in which case the Platform Suite for SAS can help. This feature can be used for scheduling and automating your SAS workload across a single server or a distributed grid environment. SAS Enterprise Scheduling is available as an add-on for single machine environments and is also a component of SAS Grid Manager for use in multiple machine environments. Some of the features for SAS Grid Manager include:

  • Create SAS workflows and schedule them based on time and file events
  • Combine multiple related SAS programs and other SAS jobs into a job flow
  • Define the order in which the jobs in the job flow executes
  • Specify that a job execute, or not, depending on the status of an earlier job in the flow
  • Trigger a job flow to start based on the existence or age of a file
  • Manage resource requirements and provide for load balancing through Platform LSF (Load Sharing Facility)


SAS® Scheduling: Getting the Most Out of Your Time and Resources is a great whitepaper to get you started. Please see Platform Suite for SAS for more information scheduling in a grid environment.

I hope this has been a helpful overview of your scheduling options within SAS. I also hope this frees up some of your time and your analyst’s time!

Share

About Author

Wendy McHenry

Systems Engineer

Wendy McHenry is a Systems Engineer at SAS, and every day she gets to show her customers how SAS can help solve their problems. Her primary focus is on our SMB customers. Wendy has been a SAS user for over 17 years and joined SAS as an employee in the Fall of 2011. Her SAS focus areas include data management, business intelligence, and SAS Administration. In her spare time, she is a Girl Scout volunteer. Connect with Wendy on Twitter at: @wendymac98

57 Comments

  1. Hi Wendy,

    I have created a test job to run on Monday and Tuesday in SMC and Schedule.

    Adding both new time events for (Mon and Tue), But it failed to run.

    I have clicked group conditions (Run when any of the conditions occur).

    Can you please help where I'm going wrong?

    Best wishes,
    J

  2. Hello all, does anyone know if LSF on the SAS Grid has the ability to auto-trigger a SAS query based on a change in the last modified date of another SAS data set?

  3. Howard Rosenfeld on

    What if I need to schedule a SAS job to run, using Powershell? I wrote a script to start SAS and now am faced with SAS for PC wanting my username and password. Is there a way to pass those along? I know Teradata uses a Wallet system to manage this. Does SAS have something similar?

    • Chris Hemedinger
      Chris Hemedinger on

      Do you know why SAS is prompting? To connect to a database or using SAS/CONNECT? Whatever code might be triggering that, you'll need to ensure credentials are available. Of course, you don't want to put user/password in code. In Powershell, you could set as environment variables that you pass in, and use SYSGET in code to get the values. I'd need to know more about what's triggering the prompt to advise further.

  4. Hi Wendy,

    Very good article on SAS Scheduling. I am wishing to find out a bit more about option 1.

    Does it still hold for SAS installations on a server?

    I would like to export some SAS code from SAS miner and run it in a batch process.

    Will appreciate a response.

      • Hi Chris,

        Thanks for your reply, just to add to the question.

        How can I create the '.bat' file if my SAS installation is on a server and not on my local machine?

        Could you maybe give me a quick example? That will be incredibly helpful. I have access to our license file, and environment url and port number. Not sure where I can find the path and what format it should be in?

        Will appreciate any advice, thanks!

    • Thank you so much for reaching out! You could use the "Deploy SAS Data Step" program in SAS Management Console. This would then need to be done for each of your 1,000 programs! Some ideas to speed this up- you might be able to take advantage of the Java classes in the application, if you have a savvy Java programmer you could possibly loop through all of the code files you have?

      Another option could be using SAS Data Integration Studio to import your SAS code, many files at one time, into multiple SAS Jobs in the metadata. Once this is done, you could use deploySASJobs.bat to deploy them all into the Schedule Manager of SAS.

      These options might give you some ideas... Give them a try, and if you need more help, please reach out to SAS Technical Support for assistance.

      Thank you!
      Wendy

  5. Wendy,
    Is there a way to schedule SAS jobs to run at a particular time using SAS software that is running on Oracle Virtual Box running on Windows OS??

    Thanks!

    • Wendy McHenry

      Hi! It sounds like a Windows VM is running in VirtualBox. If so, you can log into the VM and use the same method(s) described in the blog post. The only caveat is the VM needs to be running (powered on) during the time of the scheduled task.

      Hope that helps!
      Thanks,

      Wendy

  6. Keith Johnson on

    Thanks for the post, I can totally get the base process to work as shown, however I have a process that take some 4 hours of processing time that I run via a task manager and wanted to add a date-time log to and a parameter option to keep any random co-worker from accidently running this when not needed. That all seems to be working somewhat okay (logging not what I expected but it's okay) I am willing to share that if useful to the blog readers. What is very strange is the original program creates a report not just a data set, that report will auto create a name of the SAS program name minus '.sas' a date stamp and .xlsx via manual runs. Now in the batch, without SAS original code change, the report is just '_date stamp.xlsx' My questions does anyone have any idea why the name of my report file fails to generate and a way to fix that will work in both manual running of this SAS program and batch running? Here is my SAS code that calculates the name if it helps:
    %macro fdate(fmt);
    %global fdate;
    %global tdate;
    data _null_;
    call symput("fdate",left(put("&sysdate9"d,&fmt)));
    call symput("tdate",left(put(today(),&fmt)));
    run;
    %mend fdate;
    %fdate(yymmddp10.) ;
    %put &fdate ;%put &tdate ;

    %Let FName = %SysGet( SAS_EXECFILEPATH ) ;
    %put &fname;
    %let sasfile= %sysget(SAS_EXECFILEname);
    %put &sasfile ;
    %let odsfile=%qsubstr(&sasfile,1, %length(&sasfile)-4);
    %put &odsfile;
    %Let PName = %qsubstr(%sysget(SAS_EXECFILEPATH),1, %length(%sysget(SAS_EXECFILEPATH))-%length(%sysget(SAS_EXECFILEname))) ;
    %put &pname;
    %let outputfile=&odsfile._&tdate..xls;
    %put &outputfile;

    'outputfile' is given to the ODS code as the 'file = &outputfile.;' parameter

    PS the batch code does this with the base example and my expanded use (adding log and parameter option), so I assume I have not broken anything with my additions, but of course am not 100% sure on this point. If needed I can send my batch along for review.

  7. Option to run thru task scheduler is ok for test, using the "Platform Suite for SAS" good idea but, now have to use another schedule package different than one being used as the "System wide scheduler" is that available with use of SAS EG along with load balancing, proper sequence scheduling and error checking prior to scheduling another process? This might not be correct forum for this question but, looking for a solution controlling several hundred processes that run daily. Thanks!

  8. Hi Wendy,

    i have been trying to use the first method using the bat file. but every time it throws text file access error saying "An error occurred while attempting to access the text source file.This maybe due it being locked by,or open in another application.The data cannot be imported until situation is resolved."

    The sas file is always closed while using and there is nothing to be locked by.Below is the content of my txt file:
    C:\Program Files\SASHome2\SASEnterpriseGuide\7.1\SEGuide.exe" -SYSIN "C:\TRACKING.SAS"
    I am using SAS EG currently I have removed log and output part as they also throw up errors .

    Please suggest,Thanks.

    • RODRIGO DE OLIVEIRA SILVA on

      -SYSIN é uma variavel de ambiente do SAS versão 9, acredito que não tenha a pasta bin no SAS versão.

  9. Hi Wendy: Great post. Question for you. I have created a .bat file where I want to call multiple sas programs in sequence. I have separated each line by a hard return. This is not working - what do you advise? Thank you.

    • Hi Patty,

      Thanks for your question! Your .bat file should be structured like the example under #1. If you have been able to get your .bat file working with a single program, then you'll want to make sure your format for multiple programs is such as in #1. If the .bat file doesn't work for a single program, I would call SAS technical support for guidance on the appropriate call command for your SAS System.

      Thank you!

      Wendy

  10. Hi Guys,Though this is an old post,hope someone is still active here. I am currently using windows scheduler to run SAS scripts without having user to login to the system. The user is with admin privileges but now i need it to run the same way (scheduling and running without login to the system) without administrator privileges. please let me know if it possible and how if yes.
    Thanks

  11. Hi Wendy,

    Thank you for the information on scheduling the SAS Programs option stated below.
    I would like to schedule SAS EG projects and Programs in SAS Unix server to avoid the EG session disconnection due to the network firewall keep alive been set up for 55 min (security concern).
    In my system users connect to SAS remotely as SAS (Non Grid) is installed in remote location.
    So if my users run the SAS EG project or Programs in EG which run for more than 1 hour its get disconnect. I have already scheduled the sas program in UNIX server, it’s similar to Option #1 like created .sh file with install path, .sas file path and log path in SAS UNIX server. Then I have mapped this in corncob to run once in 10 min.
    My question:
    How to schedule SAS EG projects in UNIX server? i guess i can not go with the Option#2 as i dont want launch EG and run the program in User PC cause again it would face disconnection issue after 55 min.
    Can I schedule the SAS EG project or programs using SAS Management Console?
    I think the Option#4 you have shared above is for Grid- am I correct?

    Thanks,
    Ram

  12. Scheduling is always an hot topic in SAS and after reading some of these comments from EG users it might be time to let SAS EG use the Management Console Scheduler. It would allow people to run and schedule jobs and also make it easier for the SAS Admin as well. Perhaps a new feature request.

  13. Hi Shree,

    Thank you for your question! SAS can be scheduled on that remote SAS installation. If you have a SAS Administrator, I would reach out to them for assistance on getting your report scheduled. Otherwise, SAS Technical Support would be happy to assist.

    Thank you!
    Wendy

  14. shrenidhi k S on

    Hi Wendy,

    I hope you are still active here!
    Thanks for awesome info!
    In my system SAS is installed remotely. everyday we need to run a signon script before we do any work.
    but I have a daily report which I must run
    can I automate this using scheduler?

    Best wishes,
    Shree

  15. Wendy,

    When you schedule a sas program in batch, or schedule a project in EG, will the program run in the background, or do you need to have EG running on your local machine?

    Thanks.

  16. Hi Wendy,
    I am currently trying to automate few SAS EG reports. I scheduled the SAS EG project from which a VBScript is generated. Then I wrote a batch file with cscript.exe path(from local system) and the Vb script path which generated from SAS EG project.
    Till now I have tested and everything is good, reports are getting generated in my designated folder automatically. Till now I tested them on my local system, Windows task scheduler and it worked fine.
    And now my question to you is..., I will be using the batch file and integrate it with Tidal scheduler in the server.
    What are the things which needs a change for running the reports on a server automatically. Please need your help on this.
    Thanks a lot in advance...

    • Hi Diana,

      With the information you've provided, here are the things I would make sure you have on the server:

      * All the same SAS components licensed and installed on the server as you had on your PC.

      * Find the location where you need the SAS code to be stored, any libraries created in SAS Metadata, and any locations where you need any output to be placed.

      * Open the Enterprise Guide project on the server side, and go into Project Maintenance. From this screen, you can update the libraries and the server where the project is running.

      * Update any libraries and folder locations to be those on the server.

      I hope that is helpful! For further assistance, I'd recommend reaching out to SAS Technical Support who can help also.

      Thanks,

      Wendy

  17. I have to schedule a SAS job (which was earlier running by TIDAL) into Cronacle. The .sas file is called by within a .bat file, I guess its option 1 from this post.
    Is anybody aware of any special considerations to schedule a SAS job of Windows server into Cronacle.
    There is a %errorlevel% check in the batch file and that gives a value 301, thereby aborting the program. Please note that if not run through Cronacle, the sas job runs absolutely fine so it might not be a code error.

    I am getting the following error message in standard output file

    Error: OCS environment variable not set
    Any thoughts and suggestions are appreciated

  18. Wendy - thank you so much for this information!

    I am using the Windows Task Scheduler (option 1) and my program successfully runs if I double click the .bat file, and when I run it manually in base SAS. However, when the scheduler automatically invokes the .bat file, I get a pop up saying that "pcfserver.exe has stopped working" and my program fails. My program is not complicated, it is just a PROC IMPORT of a .xlsx file. My SAS is older, version 9.2.

    The issue happens in SAS Enterprise Guide. I can run the PROC IMPORT manually as a program, and it is successful. However, when I run it as a process flow, I get the pop up "pcfserver.exe has stopped working" and my program fails.

    Any ideas on how to fix it? I do have the PC Files Server component installed (which is how I am able to successfully run the program manually). It seems to be when I use another application to execute the program, I get the error.

    Thanks so much!

    • Hi Kelsey,

      To run the program as written, it will need the SAS Access Engine to PC File Formats installed and licensed in the location where it is running.

      If you do have the SAS Access Engine to PC File Formats installed there, your best bet is going to be to contact SAS Technical Support to fix the issue.

      I hope that helps!

      Thank you so much,

      Wendy

    • Peter Lancashire on

      Check that the current directory is set correctly. You will need to do this in your *.bat file. Also check that any required Windows batch environment variables are set. If you are not clear what is happening in the task scheduler job, set up a simple one to write out the current directory and environment to a known file and examine that: cd >C:\file.txt set >>C:\file.txt

      Note: if you name your file *.cmd instead of *.bat you will have access to some more sophisticated batch facilities in Windows.

  19. Hi Wendy
    Very helpful post thank you. How would one find the path for the sas.exe of university edition? Or basically to create a *.bat file like option one. I can't imagine localhost:10080 working.
    Thank you
    Con

  20. Hi Wendy,

    I've scheduled many SAS projects in SAS Enterprise Guide 4.2 in Win20003, but now my system was changed to Win2007, when I do the same schedule in “Task Scheduler” for the EGScript, but it was showing"Running" all the time, but the SAS code was not ran? Do you know the reason?

  21. Kapil Shahani on

    Hi Wendy,

    We use Virtual connections system to connect to our systems. Because of which we can not use Windows Scheduler as we may or may not connect to the same system on the next login. We use EG 4.2 which is set up on Unix System. Administrator rights for Unix has not been provided to us.

    I want to schedule as many as 200-300 jobs (sas programs) on the system. As I don't have Windows Scheduler and admin rights on Unix, what is the best method for me to schedule these jobs?

  22. Hi Wendy,

    Thanks for writing about the scheduling within SAS. I'm keen to setup some automation using an Operating System Scheduler on Linux. Everything is setup from a scheduler perspective, but I can't find any documentation on which directory I am meant to deploy my SAS batch jobs to?

    Cheers

    Paul

  23. Hi Ram,
    Thanks for writing! You should not need admin rights to use the Windows Scheduler. However, you do need to ask your IT department for access to the Windows Scheduler.
    Once you have those in place, please contact SAS Technical Support for further assistance.
    Thank you!
    Wendy

  24. Hi Wendy,

    Thanks for the post.

    I m using EG 4.2 and followed the steps as per little sas book.

    But problem for me is I dont have a Windows scheduler admin rights to trigger them.

    Without using windows schedules how do I run the project?

    Any help will be really helpful.

    Best
    Ram

  25. Dear Wendy,
    Would wou allow me to publish on my French blog on SAS a translated version of this article?
    Best Regards,
    Véronique

  26. Chris Hemedinger
    Chris Hemedinger on

    Wendy - thanks for writing on this topic. Batch jobs are a long-standing strength of SAS programs, and it's good for people to see the many ways that a job can be run/scheduled.

    • Wendy McHenry on

      Thanks, Chris! I hope that it is useful. I started off as a batch job user and now use Management Console myself, and sometimes I find folks need the more advanced features that are found in Platform Suite for SAS.

Leave A Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to Top