Hello
I want to create a batch file (in notepad) which is a .bat file
I want to use this batch file in order to run automatically a sas program every day.
Let's say that the sas code that I want to run is a simple and short code:
proc sql;
create table as class
select *
From sashelp.class
;
Run;
My question:
What should I write in the batch file in order to run this program on SAS?
Should I tell first to open SAS and then to run the code?
Should I put the SAS code (that I wrote before) in the batch file?
Please note that then I want to use Windows task scheduler with related to this batch file
Automating SAS processes using Windows batch files - SAS Users
Here is the content you should write in BAT file.
"C:\Program Files\SASHome\SASFoundation\9.4\sas.exe" -nosplash -sysin "c:\temp\temp.sas" -log "c:\temp\temp#Y#m#d-#H-#M-#s.log" -logparm "rollover=auto"
Thank you.
As I see you didnt write the SAS code into the bat file.
Did you write the path where the sas program is located?
Thanks,
In the code you sent me ti write in the batch file (bat file).
Where is the directory of the sas program that I want to run ?
"C:\Program Files\SASHome\SASFoundation\9.4\sas.exe" -nosplash -sysin "c:\temp\temp.sas" -log "c:\temp\temp#Y#m#d-#H-#M-#s.log" -logparm "rollover=auto"
In the example given, the path following -sysin is the program name.
@Ronein wrote:
Thanks,
In the code you sent me ti write in the batch file (bat file).
Where is the directory of the sas program that I want to run ?
"C:\Program Files\SASHome\SASFoundation\9.4\sas.exe" -nosplash -sysin "c:\temp\temp.sas" -log "c:\temp\temp#Y#m#d-#H-#M-#s.log" -logparm "rollover=auto"
@Ronein wrote:
So only this part need to be modified (by the program path name )?
"c:\temp\temp.sas"
All other parts in the code are fixed?
If your SAS runs on Windows, and is installed in the default path. If your SAS server is using UNIX, the path names will be very different.
"C:\Program Files\SASHome\SASFoundation\9.4\sas.exe" -nosplash -sysin "c:\temp\temp.sas" -log "c:\temp\temp#Y#m#d-#H-#M-#s.log" -logparm "rollover=auto"
what is "C:\Program Files\SASHome\SASFoundation\9.4\sas.exe" ?
Is it the path where SAS is located?
What is the meaning of -nosplash
What is the meaning of -sysin?
What is "c:\temp\temp.sas"?
Is it the path of SAS program that I want to run?
What is -log "c:\temp\temp#Y#m#d-#H-#M-#s.log" ?
IS it the location of the log file that should be created once run the sas program?
What is -logparm "rollover=auto" ?
Is it essential that the batch file (.bat) will be saved in same location of sas program file?
You save your code as a text file with extension .sas.
How you run this in batch depends on your SAS environment. If client/server, run it with the sasbatch script provided in the BatchServer directory of the configuration tree.
You mean that I need to save my SAS program ?
As I know SAS program is alway end with .SAS end.
The question is what to write in the bat file (in notepad) in order to run this program?
Then I want to create windows scheuler to run it every day auatomatically
@Ronein wrote:
You mean that I need to save my SAS program ?
As I know SAS program is alway end with .SAS end.
No. A .sas file ends where it ends, without a special command. .SAS end would cause a syntax ERROR.
The question is what to write in the bat file (in notepad) in order to run this program?
Then I want to create windows scheuler to run it every day auatomatically
The script (or batch) file needs a line like
<path to your SAS executable or batch script> <fully qualified path to program>.sas -log <fully qualified filename of log>.log
Add more options as needed. Read the documentation for running SAS in batch mode.
Which command to use for starting SAS depends on your SAS setup, so we MUST KNOW THAT!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.