SAS users commonly have the need to repeatedly execute sas programs and efficiently perform log scans.we discuss one simple method that uses windows batch(*.bat) files to submit sas program
1. Sample Directory structure
2.SAS file(include main.sas & program.sas)
code for main.sas:
- %macro Program_initial;
- filename fileref pipe "cd";
- %put &Root;
- data Root;
- infile fileref pad;
- input Root $200. ;
- call symputx('Root',Root);
- newdir=dcreate('work',"&Root");
- newdir=dcreate('result',"&Root");
- run;
- libname worklib "&Root/work";
- filename result "&Root/result";
- %include "&Root/program.sas";
- %mend;
- %macro Program_Main;
- %Program_initial;
- ods listing close;
- ods html path=result(url=none) file='index.html' ;
- /*===============================*/
- /*画图全局控制*/
- ods graphics on / reset border=off;
- /*===============================*/
- %program;
- ods html close;
- %mend;
- %global Root;
- %Program_Main;
- %macro dataproc;
- data worklib.a;
- set sashelp.heart ;
- run;
- %mend;
- %macro drawproc;
- proc sgpanel data=sashelp.heart noautolegend;
- title "Cholesterol Distribution in Heart Study";
- panelby sex;
- histogram cholesterol;
- density cholesterol;
- run;
- proc sgscatter data=sashelp.iris;
- title "Scatterplot Matrix for Iris Data";
- matrix sepallength petallength sepalwidth petalwidth
- / group=species;
- run;
- title;
- %mend;
- %macro program;
- %dataproc;
- %drawproc;
- %mend;
3.Creating and using sasauto.Bat file
code for sasauto.bat ,you may need to change the installation path "C:\Program Files\SASHome\SASFoundation\9.3\sas.exe "
- @ECHO OFF
- SET /P FOLD=Enter Specific Project(i.e. P001)
- rem set /p ANALYSIS=Batch Analysis Programs?(Enter Y for yes ,Otherwise hit enter)
- rem ECHO Analysis Programs Batch Indicator=%ANALYSIS% >> Batch-Summary.txt
- rem set /p GRAPHS=Batch Graph Programs?(Enter Y for yes ,Otherwise hit enter)
- rem ECHO Graph Programs Batch Indicator=%GRAPHS% >> Batch-Summary.txt
- ECHO Project=%FOLD%>>Batch-Summary.txt
- ECHO Start:%DATE%: %TIME%>>Batch-Summary.txt
- "C:\Program Files\SASHome\SASFoundation\9.3\sas.exe" -sysin main.sas -nolog -nologo -icon -rsasuser
- ECHO End:%DATE%: %TIME%>>Batch-Summary.txt
- explorer result\index.html
4.Run the bat file
(1) Initial Directory Environment
del the file "work" "result" which will recreate by main.sas
double click the sasauto.bat,input your program name and press enter
view the result in dir "result/index.html"
5.check the efficient
本帖隐藏的内容
sastest.rar
(1.17 KB, 需要: 1 个论坛币)



雷达卡



支持原创!
京公网安备 11010802022788号







