As the first step in the decommissioning of the site has been converted to read-only mode.

Here are some tips for How to share your SAS knowledge with your professional network.

Batch processing under Windows

From sasCommunity
Jump to: navigation, search

As part of the decommissioning effort for this article/tip has been migrated to

The new home for this article/tip is Batch processing under Windows (

Batch Processing under Windows


DOS: Disk Operating System

Open a Command Prompt window and type help

C:\Documents and Settings\[UserId]>help

For any command on the list

C:\Documents and Settings\[UserId]>help start

from SAS-L discussion of 2008-Oct-16:

  • Subject: RE: Limiting task CPU allocation in Windows?
  • From: Phil Rack


The DOS start /low command allows you to change the priority class of the SAS job.

One other thing I would like to add is that if you are running a multi-core processor, you might want to set the affinity for a certain process or program to use just a single core. I don't know how to do this in a batch program, but you can do this in the same manner as setting a programs priority in task manager.

You can use a third party tool from beyond logic to do this from a batch file/command prompt. end(quote)

Files Needed

You will need the following files in your project folder in order to run sas programs in batch mode.


"C:\Program Files\SAS\SASfoundation\9.2\SAS.exe" %*


"C:\Program Files\SAShome\SASfoundation\9.3\SAS.exe" %*
rem "C:\Program Files\SAShome\SASfoundation\9.3\x64\SAS.exe" %*


RJF 2017-Oct-31 rename this file from sas.bat to sas.cmd

rem    name: sas.cmd for either V8 or V9
if not exist "C:\Program Files\SAS\SAS 9.1\SAS.exe" goto v8
             "C:\Program Files\SAS\SAS 9.1\SAS.exe" %*
goto EOF
    "C:\Program Files\SAS Institute\SAS\V8\SAS.exe" %*
rem        note:      SASv9.1.3        %*: pass all invocation parms
rem description: pass all command line parms to SAS 
rem     purpose: select SAS version, 
rem        note: single point for SAS version selection for all *.bat
  • Note that '%*' (percent-sign asterisk) is the Windows command

that passes all command-line parameters to sas.exe.

  • Note that the first parameter is sysin, otherwise it has to be named, e.g.:
sas -echoauto -sysin my-program


command-line or startup options

/*name: SASv9.cfg basic*/
-SASinitialFolder '.'

-noovp      /* no overprint errors nor warnings */
-nosplash   /* no display SAS banner at startup */
/*name: SASv9.cfg advanced: write log and listing to separate folders*/
-SASinitialFolder '.'
-log              '..\log'
-print            '..\lst'

This is a fix for redirecting your work area to another folder.

  • find this file in sasroot:
    • C:\Program Files\SAS\SASFoundation\9.2\SASV9.CFG
  • copy the file! so you have a back-up
  • edit SASv9.cfg: is.a text file: open with NotePad

the original looks like this

-CONFIG "C:\Program Files\SAS\SASFoundation\9.2\nls\en\SASV9.CFG"

add reassignments of

  • environment variable
    • mysasfiles
  • options
    • sasuser
    • work

orginal values; CSIDL_Personal and TEMP are Windows environment variables.

/* Setup the MYSASFILES system variable                         */

/* Setup the default SAS System user profile folder             */

/* Setup the default SAS System user work folder                */
-WORK "!TEMP\SAS Temporary Files"

replace with these suggestions:

/*name: SASv9.cfg in !sasroot */
/* 1. call the primary configuration file */
-CONFIG "C:\Program Files\SAS\SASFoundation\9.2\nls\en\SASV9.CFG"

/*2. resets */
/* Setup the MYSASFILES system variable                         */
-SET MYSASFILES 'C:\temp\MySASfiles'

/* Setup the default SAS System user profile folder             */
-SASUSER 'C:\temp\MySASuser'

/* Setup the default SAS System user work folder                */
-WORK 'C:\temp\MySASwork'

see also:

  • C:\Program Files\SAS\SAS 9.1\SASV9.CFG
  • C:\Program Files\SAS\SAS 9.1\nls\en\SASV9.CFG
  • C:\Program Files\SAS\SASfoundations\9.2\nls\en\SASV9.CFG


These two files will generate a log that will list everything you ever wanted to know about entries made into the Global Symbol Table during startup.

rem sasv9-cfg-test.bat
sas sasv9-cfg-test -verbose


Note: that sasv8.cfg must have the primary sasv8.cfg named. Compare to sasv9.cfg, where this is no longer a requirement.

/*name: SASv8.cfg */
-config 'C:\Program Files\SAS Institute\SAS\V8\SASv8.cfg'
-SET                ProjRoot     'C:\SASProjects\ProjectA'
-SASinitialFolder '!ProjRoot\sas'

-noovp      /* no overprint errors nor warnings */
-nosplash   /* no display SAS banner at startup */

You need to know:

Proc Options define value option = autoexec;
Proc Options define value option = echoauto;

... how to provide the name of an autoexec file in a batch file:

sas MyProgram -autoexec

Note: needs quotes if directory-spec contains spaces.

... how to provide the name of an autoexec file in a configuration file:

-autoexec "S:\SAS Projects\Project Alpha\"

see also: AutoExecTest

SAS searches the folder containing a program for an; if if finds one, then the statements are executed before the program.

To point SAS to a folder from an icon append the option sasinitialfolder to the Target:

-sasinitialfolder "S:\SAS-Projects\Project-Alpha"


This is a setup for including programs in the same folder and storing data sets and format catalogs in a sibling folder.

Title 'Our Company, This Project';
Filename Project '.'       ;%*here;
Libname  Library '..\sas7b';%*data and format catalogs;
Options nocenter;

Using Includes:

%Include Project(ProgramA);
%Include Project(ProgramB);

Advanced Macro Use: AutoCall

This is a setup for autocall of project and site macros:

Title 'Our Company, This Project';
Filename Project  '.'       ;%*here;
Filename SiteIncl 'S:\SASsite\includes'; * server;
Filename SiteMacr 'S:\SASsite\macros';   * server;

options mautosource  %*autocall;
        sasautos  = (Project SiteMacr SASautos);

Libname  Library '..\sas7b'; %*data and format catalogs;

Options nocenter;

Advanced setup for autocall of development, testing and production project and site macros:

Title 'Development';
Title 'Testing';

Filename Project  '.'       ;%*here;
Filename SiteIncl 'S:\SASsite\includes'; *server;

Filename SiteMDev 'S:\SASsite\macros\Development';
Filename SiteMTst 'S:\SASsite\macros\Testing';

Filename SiteMacr 'S:\SASsite\macros';   * production;

options mautosource  %*autocall;
        sasautos  = (Project 
                     SiteMacr SASautos);

Libname  Library '..\sas7b'; %*data and format catalogs;

Options nocenter;

Advanced Macro Use: Compiled and Stored in Catalog

This is a setup for usage of compiled and stored macros for production jobs.

*compiled and stored SiteMacr.SASmacr.catalog;
libname              SiteMacr '<directory-specification>';
options sasmstore =  SiteMacr mstored;

For examples see: SASautos_Companion_Reusing_Macros

See also: Setting_Up_Project_Config_and_AutoExec

Advanced Usage: Setting Environment Variables

You can use environment variables as Global Project Constants.

recommendation: max(length(Evar-name)) le 8;

options set = Evar "value";
%Put note: Evar:%sysget(Evar);

*note.1: quotes may be either of single- or double-quotes; 

options set = EvarSQ 'value in single quotes';
%Put note: EvarSQ:%sysget(EvarSQ);

*note.2: provide list of values, such as folders in parenthesis:;
options set = folders ("folder.1" "folder.2");

*note.3.1: check length of evar names;
*note.3.2: in earlier R&D I found max(length(Evar-name)) is 12;
options set = Evar5678901234  "Value6789012345";
%Put note: Evar-14:%sysget(Evar5678901234);

*note.3.3: while this assignment works ...;
options set = Evar56789012345  "Value6789012345";
%Put note: Evar-15:%sysget(Evar56789012345);

options set = Evar56789012345678901234567890123 "Value33";
%Put note: Evar-33:%sysget(Evar56789012345678901234567890123);

*note.3.3: this listing shows corruption of longer names;
*proc options define value option = set;
proc options option = set;

Environment variables may be assigned in a configuration file. This example shows the syntax.

/*syntax for using set in configuration file */
-set Evar "value"
-set EvarSQ 'value in single quotes'

Program Name

Q: What program is executing? i.e.: does MyProgram know its own name?

%let FileNameExt = %sysget(SAS_EXECFILENAME);
%let FolderFileNameExt = %sysget(SAS_EXECFILEPATH);

Note the above are Windows environment variables.

Title2 "Folder\program %sysfunc(getoption(SysIn))";
Title3 "program name:%scan(%sysfunc(getoption(SysIn)),-1,\);

Want to know program name whether you are running in batch or interactive?

Use the ifc function to provide the correct name.

%Let FolderFileNameExt = %sysfunc(getoption(SysIn));
%sysfunc(ifc(       "&FolderFileNameExt." ne ""
        )   )
;*end titleN or footnoteN statement;


Usage: add to SASv9.cfg in either SASroot or project

/*name: SASv9.cfg in !sasroot */
/* 1. call the primary configuration file */
-CONFIG "C:\Program Files\SAS\SASFoundation\9.2\nls\en\SASV9.CFG"

/* 2. create environment variable of site folder 
      note: used by */
-set        SiteAutos 'C:\SAS-site'
-autoexec '!SiteAutos\sas\'
 /* name   : AutoExecSite;
description: site autoexec, called by configuration option autoexec
purpose    : for all projects
             provide standard set of filenames and libnames
             if exist(Project(autoexec)) then include
   exist   : folders:
********* */
%Let AesSysIn         = %sysfunc(getoption(SysIn));
%Let AesJobName       = %scan(&AesSysIn.,-1,\/);
%Let AesJobFolder     = %sysfunc(tranwrd(&AesSysIn.,&AesJobName,));
%Let AesProjectFolder = %sysfunc(tranwrd(&AesJobFolder.,\sas\,));
filename Project  "&AesJobFolder.";
filename SiteIncl '!SiteAutos\includes';
filename SiteMacr '!SiteAutos\macros';
libname  SiteLib  "&AesProjectFolder.\sas7b";
* note: project autoexec allocates libref Library for use in:
options fmtlib = (Work Library SiteLib);
options  sasautos = (Project
* if exist(Project( then %include;
            ,%nrstr(%Include Project(autoexec)/&AesSource2.;)
            ,%nrstr(%Put Note: not exist Project(autoexec) ;) ))
%symdel AesJobName AesJobFolder AesProjectFolder
        AesSource2 AesSysIn     AesTesting;


rem AutoexecTest.bat
sas AutoexecTest -echoauto -linesize max -pagesize max -verbose
* name:;
* Everything you wanted to know about your sas session;
* Or: Way More than you wanted to know!;

* RJF2 2008-Nov-19 added information about JRE;
%put note: Win environment variables;
%put %sysfunc(getoption(set));
%put SASJreRoot:%sysget(SASJreRoot));*NOTE: E-var MAY NOT BE ALLOCATED;
%put JREoptions: %sysfunc(getoption(JREOPTIONS));
PROC JavaInfo;

* RJF2 2008-Nov-19 added information about Sudaan;
PROC Options define value option = HelpRegister;
PROC Options define value option = Path;
%put SudaanDlls:%sysget(SudaanDlls));*NOTE: E-var MAY NOT BE ALLOCATED;

* write Sys* macro variables;
%put _automatic_; 
Filename _All_ list;
Libname  _All_ list;
PROC SetInit;
PROC Options;

See related discussion of JRE: Java_JRE_1.5.

Program Examples


rem MyProgram.bat
sas MyProgram


  • sas refers to sas.bat
  • MyProgram, as first parameter is parsed as SysIn

This is short form of:

sas -SysIn MyProgram

Using command-line parameter:

sas -SysIn MyProgram -SysParm 'parameter'

Treating SysParm as csv: Comma Separated Values

sas -SysIn MyProgram -SysParm 'parameterA=valueA,parmB=valueB'

See Parse_sysparm for a program to extract global macro variable from csv in SysParm.

For other command-line-only options:

sas -SysIn MyProgram -<optionname> <<optionvalue>>
* name:;
proc print data = sashelp.class;


  • MyProgram.log
  • MyProgram.lst


rem MyProgram-Test.bat
sas MyProgram-Test
* is a parameterized include file;
%Let Data = sashelp.class;
%Include Project(MyProgram);

%Let Data =;
%Include Project(MyProgram);
* is a macro;
%MyProgram(Data = sashelp.class)
%MyProgram(Data =;


This batch file executes two other .bat files for programs MyProgram1 and MyProgram2. Note that these are calls to MyProgram1.bat and MyProgram2.bat.

call MyProgram1
call MyProgram2

To call sas programs that do not have their own .bat files:

call sas MyProgram1
call sas MyProgram2


> From: Behalf Of Scott Bass
> Sent: Friday, October 03, 2008 2:56 AM

basic DOS batch file processing:

rem command line only

for %f in (*.sas) do call sas "%f"

rem In a batch program this is a do loop:

for %%f in (*.sas) do sas "%f"  

Note: double percent signs (%%f) is correct.

command-line options

see also options:

options: log or altlog

Options Log and AltLog are command-line only options.

Proc Options              Group  = EnvFiles;
Proc Options define value option = log;
Proc Options define value option = altlog;

Here are SASv?.cfg additions for redirecting logs to another folder

Note: the argument to the option may be a directory-specification.

This directs the program log to another folder

-log    '..\log'    /* ..\log\MyProgram.log */

This directs a copy of the program log to another folder

-altlog '..\altlog' /* ..\altlog\MyProgram.log */

Note: the argument to the option may also be a file-specification.

-log '..\log\MyProgram.log'

In my own practice I would write different logs based on value in SysParm:

rem      MyProgram.bat
call sas MyProgram -SysParm 'A' -log 'MyProgram-Sysparm-A.log'
call sas MyProgram -SysParm 'B' -log 'MyProgram-Sysparm-B.log'

Session Setup to run a Project batch program

Q: How do a submit a program set up to run in batch from a session?

A: A program in a project has an autoexec which allocates project filerefs and librefs.

When starting a SAS session the default File-Open folder is ClassDoc. This program shows how to change the default folder (see option SASinitialFolder) to the project folder, submit the autoexec, and then any program within the project.

* name:;

options source2; * view statements;

* process: location of programs;
x "cd C:\SAS-projects\ProjectA\sas";

* set project defaults;
%Include ''; * allocates fileref Project;

* process: name of program;
%Include Project(SE1Calc);  


created by User:Rjf2 15 June 2007 (EDT)

Ronald_J._Fehd macro.maven == the radical programmer