Ora

How to Log Into a SAS Batch Job

Published in SAS Batch Processing 6 mins read

"Logging into" a SAS batch job isn't an interactive login in the traditional sense. Instead, it refers to configuring the server and user permissions for a specific account to execute SAS programs non-interactively, and then submitting those programs for processing. This ensures the batch job runs successfully in the background, often on a server.

Understanding SAS Batch Job Execution

A SAS batch job is a non-interactive execution of a SAS program. It typically runs without a graphical user interface, processing data and generating output files (like log files, data sets, or reports) automatically. For a SAS batch job to run, the operating system user account under which the job will execute must have specific permissions on the server.

Essential Pre-configuration: The "Log on as a Batch Job" User Right

One of the critical prerequisites for any user account to run SAS batch jobs on a Windows server is the "Log on as a batch job" user right. This security policy grants the necessary permissions for an account to initiate batch processes.

Granting the "Log on as a Batch Job" User Right

To ensure your Windows user ID or a relevant SAS service account can execute batch jobs, follow these steps:

  1. Open Local Security Policy:

    • Press Win + R to open the Run dialog.
    • Type secpol.msc and press Enter. This will open the Local Security Policy editor.
    • Credible Source: Microsoft Documentation on Local Security Policy (Note: This is a placeholder for official Microsoft documentation.)
  2. Navigate to User Rights Assignment:

    • In the left-hand pane of the Local Security Policy window, expand Local Policies.
    • Select User Rights Assignment.
  3. Configure "Log on as a batch job":

    • In the right-hand pane, locate and right-click Log on as a batch job.
    • Select Properties from the context menu.
  4. Add User or Group:

    • In the "Log on as a batch job Properties" window, click Add User or Group...
    • Add your specific Windows user ID that will be submitting or running the batch jobs.
    • Alternatively, you can add a group, such as SAS Server Users (if your SAS installation uses such a group for its service accounts), or the Windows group that contains the user accounts designated for running SAS services or batch processes.
    • Click Check Names to verify the entry, then OK to add it.
    • Click Apply and OK to close the properties window.

Why is this important? This right is a fundamental security setting that dictates which user accounts are permitted to perform non-interactive logon tasks, such as running scheduled jobs or services. Without it, the operating system will prevent the batch job from starting under that user's context, leading to errors.

Submitting a SAS Batch Job

Once the necessary server permissions are in place, you can submit your SAS program for batch execution. There are several common methods:

1. Command Line Submission

The most direct way to run a SAS batch job is via the command line of the server where SAS is installed.

  • Windows Example:

    "C:\Program Files\SASHome\SASFoundation\9.4\sas.exe" -SYSIN "C:\MySASPrograms\MyBatchProgram.sas" -BATCH -LOG "C:\MySASLogs\MyBatchProgram.log" -PRINT "C:\MySASReports\MyBatchProgram.lst"
    • -SYSIN: Specifies the path to your SAS program file (.sas).
    • -BATCH: Instructs SAS to run in batch mode (non-interactive).
    • -LOG: Specifies the path for the SAS log file. This is crucial for debugging and monitoring.
    • -PRINT: (Optional) Specifies the path for the SAS output file.
  • Unix/Linux Example:

    /opt/sas/SASHome/SASFoundation/9.4/sas -sysin /home/sasuser/programs/myprogram.sas -batch -log /home/sasuser/logs/myprogram.log -print /home/sasuser/reports/myprogram.lst

2. Using Job Schedulers

For regular, automated execution, integrating your SAS batch jobs with an operating system job scheduler is highly recommended.

  • Windows Task Scheduler:

    1. Open Task Scheduler (search for it in the Start menu).
    2. Create a new Basic Task or Create Task.
    3. Define the trigger (e.g., daily, weekly, specific time).
    4. For the Action, select "Start a program" and specify:
      • Program/script: Path to sas.exe (e.g., "C:\Program Files\SASHome\SASFoundation\9.4\sas.exe").
      • Add arguments (optional): The SAS options (e.g., -SYSIN "C:\MySASPrograms\MyBatchProgram.sas" -BATCH -LOG "C:\MySASLogs\MyBatchProgram.log").
    • Crucially, under the General tab of the task properties, ensure the task is configured to "Run whether user is logged on or not" and specify the user account (which has the "Log on as a batch job" right) that will execute the task.
    • Credible Source: Microsoft Documentation on Task Scheduler (Note: This is a placeholder for official Microsoft documentation.)
  • Cron (Unix/Linux):

    • Edit your crontab using crontab -e.
    • Add an entry like:
      0 2 * * * /opt/sas/SASHome/SASFoundation/9.4/sas -sysin /home/sasuser/programs/myprogram.sas -batch -log /home/sasuser/logs/myprogram.log

      This example runs the job daily at 2:00 AM.

    • Credible Source: Linux Manual Page for Cron (Note: This is a placeholder for official Linux documentation.)

3. SAS Platform Tools (for SAS Viya or SAS 9 deployments)

In more complex SAS environments, you might use integrated tools for job scheduling and management:

  • SAS Management Console (SAS 9.4): Used to define and schedule jobs, often leveraging Platform Process Manager (LSF).
  • SAS Environment Manager (SAS Viya): Provides capabilities for managing and scheduling jobs within the Viya platform.
  • SAS Data Integration Studio: Can generate and schedule SAS batch jobs as part of ETL processes.

Monitoring SAS Batch Jobs

After submitting a batch job, monitoring its execution is vital:

  • Check Log Files: Always review the .log file generated by SAS. This file contains crucial information about the job's execution, including errors, warnings, and processing details.
  • Verify Output Files: Confirm that expected output files (data sets, reports) are generated and contain the correct information.
  • Operating System Process Monitoring: Use tools like Windows Task Manager or Unix/Linux top/ps commands to verify that the sas.exe or sas process is running.
  • Scheduler Logs: Check the logs of your job scheduler (Task Scheduler history, cron logs) for information on job start and completion status.

Summary of SAS Batch Job Execution

Aspect Description Key Tools/Commands
"Logging In" Concept Not an interactive login; refers to configuring user permissions for non-interactive execution. Local Security Policy (secpol.msc)
Prerequisite Permission User account must have the "Log on as a batch job" user right on the server. User Rights Assignment > Log on as a batch job
Submission Methods How to initiate the SAS program in batch mode. Command Line (sas.exe -BATCH), Windows Task Scheduler, Cron
Key SAS Options Directives for SAS to run non-interactively and manage output. -SYSIN, -BATCH, -LOG, -PRINT
Monitoring Checking the execution status and results of the batch job. SAS Log file, Output files, Task Manager/top/ps, Scheduler logs

By correctly configuring the "Log on as a batch job" user right and utilizing appropriate submission methods, you can effectively run and manage your SAS programs in a batch environment.