Batch processing under Windows
From sasCommunity
Batch Processing under Windows
TinyUrl: http://tinyurl.com/6zlqoh
You will need the following files in your project folder in order to run sas programs in batch mode.
[edit] sas92.bat
"C:\Program Files\SAS\SASfoundations\9.2\SAS.exe" %*
[edit] sas.bat
rem name: SAS.bat 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
:v8
"C:\Program Files\SAS Institute\SAS\V8\SAS.exe" %*
:EOF
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 MyProgram
[edit] sasv9.cfg
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'
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
[edit] sasv8.cfg
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 */
[edit] autoexec.sas
You need to know:
Proc Options define value option = autoexec; Proc Options define value option = echoauto; run;
... how to provide the name of an autoexec file in a batch file:
sas MyProgram -autoexec MyPersonalAutoExec.sas
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\AutoExec.sas"
see also: AutoExecTest
Basics 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 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
SiteMDev
SiteMTst
SiteMacr SASautos);
Libname Library '..\sas7b'; %*data and format catalogs;
Options nocenter;
For autoexec.sas examples see: http://www.sascommunity.org/wiki/SASautos_Companion_Reusing_Macros
[edit] AutoExecSite.sas
Usage: add to SASv9.cfg in either SASroot or project
-set SiteAutos 'C:\SAS-site' -autoexec '!SiteAutos\sas\AutoExecSite.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:
!SiteAutos\includes
!SiteAutos\macros
!SiteAutos\sas
********* */
%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 Library "&AesProjectFolder.\sas7b";
options sasautos = (Project
SiteMacr
SASautos)
mautosource;
%sysfunc(ifc(%sysfunc(fileexist(&AesJobFolder.\autoexec.sas))
,%nrstr(%Include Project(autoexec)/&AesSource2.;)
,%nrstr(%Put Note: not exist Project(autoexec) ;) ))
%symdel AesJobName AesJobFolder AesProjectFolder
AesSource2 AesSysIn AesTesting;
run;
[edit] AutoexecTest.bat
sas AutoexecTest -echoauto -linesize max -pagesize max -verbose
[edit] AutoexecTest.sas
%*Everything you wanted to know about your sas session; %*Or: Way More than you wanted to know!; %put _automatic_; run; Filename _All_ list; Libname _All_ list; PROC SetInit; PROC Options;
[edit] MyProgram.bat
sas MyProgram
[edit] MyProgram.sas
proc print data = sashelp.class;
produces:
- MyProgram.log
- MyProgram.lst
[edit] MyProgram-Test.bat
sas MyProgram-Test
[edit] MyProgram-Test.sas
* MyProgram is a parameterized include file; %Let Data = sashelp.class; %Include Project(MyProgram); %Let Data = sashelp.shoes; %Include Project(MyProgram);
[edit] MyProgram-Test.sas
* MyProgram is a macro; %MyProgram(Data = sashelp.class) %MyProgram(Data = sashelp.shoes;
[edit] MyBoth.bat
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
[edit] MyMany.bat
> From: owner-sas-l@listserv.uga.edu Behalf Of Scott Bass > Sent: Friday, October 03, 2008 2:56 AM
basic DOS batch file processing:
</pre> 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" </pre> Note: double percent signs (%%f) is correct.
[edit] command-line options
see also options: http://www.sascommunity.org/wiki/Category:Options
- echoauto
- log and altlog
- ovp: overprint errors and warnings
- print and altprint
- splash
- sysparm http://www.sascommunity.org/wiki/Category:Sysparm
- verbose
[edit] 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'
[edit] References
- http://www.sascommunity.org/wiki/Image:Fehd-Review-pcSAS-Batch-Programming.pdf
- http://www.sascommunity.org/wiki/Setting_Up_Project_Config_and_AutoExec
- http://www.sascommunity.org/wiki/Text_Editors
- Do Not Edit Below This Line, Kim Truett, info: editing SASv9.cfg http://www.lexjansen.com/pharmasug/2006/technicaltechniques/tt18.pdf
- Craig Ray, "Large-scale System Development in Base SAS(r)"
http://www2.sas.com/proceedings/sugi27/p022-27.pdf
- This page was last modified 19:51, 4 April 2008.
- This page has been accessed 1,225 times as of 2008-May-24
- This page was last modified 22:12, 24 May 2008.
- This page has been accessed 1,354 times as of 2008-Jun-05
- This page was last modified 15:03:13, 2008-06-05.
- This page has been accessed 2,098 times as of 2008-Jul-17
- This page was last modified 19:42:40, 2008-09-11.
- This page has been accessed 2,484 times as of 2008-Sep-15
--macro maven == the radical programmer, 15 June 2007 (EDT)
Categories: Best Practices | Guides | Options | SAS Code | Version 9.2
