BookmarkSubscribeRSS Feed
ijmoorejr
Calcite | Level 5
Is it possible to have cron run a .sas program without the use of a shell script?
8 REPLIES 8
ChrisNZ
Tourmaline | Level 20

Entries in crontab can be commands, they don't have to be script names.

Tom
Super User Tom
Super User

If SAS has been properly installed on your Unix system you should have a command named sas that is how you run SAS.  To run a specific program give it the name of the program as the argument.

sas myprogram.sas

Your crontab entry can be any command, so you do not need a "script".

 

One thing to watch out for with cron is that it normally will not run the normal startup commands that run when you log onto unix.  So you might need to add a command to run your startup files so that it will find the sas command or other settings your normally have when you run SAS from the command line.

ijmoorejr
Calcite | Level 5

The majority of the .ksh scripts we use in our shop that execute .sas programs, have the following line at the top:

. ~/.profile

So, if I want to run a .sas program straight from cron without the use of a script, I should create two different cron entries...one containing the line above and the other entry to execute the .sas code via the SAS command, correct?

 

 

For example,

00 5 * * 1-5 . ~/.profile
01 5 * * 1-5 sas /complete/path/to/program/sascode.sas
Kurt_Bremser
Super User

@ijmoorejr wrote:

The majority of the .ksh scripts we use in our shop that execute .sas programs, have the following line at the top:

. ~/.profile

So, if I want to run a .sas program straight from cron without the use of a script, I should create two different cron entries...one containing the line above and the other entry to execute the .sas code via the SAS command, correct?

 

 

For example,

00 5 * * 1-5 . ~/.profile
01 5 * * 1-5 sas /complete/path/to/program/sascode.sas

Positively, NO!

Both commands will run in their separate environments, the profile will be lost immediately; put both commands in a script and run that from cron.

Scripts do not bite, and they are not poisonous.

Tom
Super User Tom
Super User

@ijmoorejr wrote:

The majority of the .ksh scripts we use in our shop that execute .sas programs, have the following line at the top:

. ~/.profile

So, if I want to run a .sas program straight from cron without the use of a script, I should create two different cron entries...one containing the line above and the other entry to execute the .sas code via the SAS command, correct?

 

 

For example,

00 5 * * 1-5 . ~/.profile
01 5 * * 1-5 sas /complete/path/to/program/sascode.sas

If you want to run two commands then you should just have to put in semi-colon between them.  Doing that might be tricky, but should be possible.  

00 5 * * 1-5 . ~/.profile ; sas /complete/path/to/program/sascode.sas

 

Kurt_Bremser
Super User

@ijmoorejr wrote:
Is it possible to have cron run a .sas program without the use of a shell script?

Yes, you can, and I would strongly advise not to do it. In fact, you'll see the error of your ways very quickly.

 

For SAS programs to run properly, all kinds of configuration information is needed, which is not the case when you just use the sas executable alone. That's why the scripts that SAS provides in your Lev1 configuration directory look the way they look.

Including all the information needed on the commandline of your crontab entries will clutter up your crontab file and make it next to incomprehensible.

Create a proper script for each of your SAS jobs, and use that simple script name when editing the crontab. Within such scripts, use the sasbatch.sh from the BatchServer directory of your SAS Application Server context (most probably SASApp), as that already contains all the information needed to have the same environment that you have in Enterprise Guide or SAS Studio.

If you have the need for a configuration that is separate from your normal context, create your own config, autoexec.sas and sasbatch script file, and use that.

Tom
Super User Tom
Super User

It really depends how you have setup SAS on your server. To just run a SAS program you should be able to use the SAS command to run the program.  Now your local IT might have created a customized SAS command to account for whether you are running SAS on a single server or in a SAS/Grid installation.

 

@Kurt_Bremser your description seems more important if you are trying to use SAS application servers to run your SAS code rather than the traditional (old style?) way of running SAS.

 

That said in either environment your might need to include either code the SAS program or code that runs before the SAS program or command line options to the SAS command itself to make sure that the program is running in the environment it is designed for.

 

Kurt_Bremser
Super User

"Just run" a SAS program is most probably not what one is doing when putting jobs into the crontab; when you have arrived a that stage, there are configurations and autoexecs that need to be taken care of, log files need to be named (with timestamps in the file names) etc.

In fact, when somebody does this:

00 5 * * 1-5 . ~/.profile ; sas /complete/path/to/program/sascode.sas

it already is a shell script, only written in an awkward way (everything on one line) that makes it less comprehensible. If it needs to include all the things mentioned above, one quickly ends up with wrap-around Vogon poetry in the crontab.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 8 replies
  • 5646 views
  • 3 likes
  • 4 in conversation