BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

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

 

 

 

 

 

 

23 REPLIES 23
Ronein
Meteorite | Level 14
Thank you fot the link but I still dont know what to write in the batch file for my simple task
Ksharp
Super User

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" 
Ronein
Meteorite | Level 14

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?

 

Ksharp
Super User
Yes. You didn't need to "write the SAS code into the bat file", just use BAT file to invoke that SAS problem .You could run it under command line or other ways as Kurt said .
Ronein
Meteorite | Level 14

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" 

 

 

Kurt_Bremser
Super User

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
Meteorite | Level 14
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?
Kurt_Bremser
Super User

@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.

Ronein
Meteorite | Level 14
"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?

 

 

 

 

 

 

Kurt_Bremser
Super User

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.

 

Ronein
Meteorite | Level 14

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

Kurt_Bremser
Super User

@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!

Ronein
Meteorite | Level 14
Can you please list the questions that I need to ask the admin (Or find by myself)
in order to run sas in batch mode?
As far as I understand I need:
1-path of sas program that I want to run in the batch mode
2-SAS setup
Anything else?

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 23 replies
  • 3610 views
  • 2 likes
  • 6 in conversation