SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
GeorgeSAS
Lapis Lazuli | Level 10

Hello,

 

I  have a SAS program: test1.sas locates at  /home/mysas/test1.sas  in unix 

 

I want to create a .sh file to run this test1.sas program, please advise.

 

I need to create the .sh file because I want use crontab to schedual running the sas program.

 

Thank you!

4 REPLIES 4
Tom
Super User Tom
Super User

How would you run the program from a terminal?

The only extra thing you probably need to add is that you might need to source your startup files because the way that CRON runs your programs it does not normally run the startup files that normally run when you start your terminal session.

#!/bin/ksh
#----------------------------------------------------------------------
# Make sure that my startup files run
#----------------------------------------------------------------------
. /home/mysas/.profile
#----------------------------------------------------------------------
# Move to the directory where we want to run the progs
#----------------------------------------------------------------------
cd /home/mysas
#----------------------------------------------------------------------
# Run the programs
#----------------------------------------------------------------------
sas test1.sas 
GeorgeSAS
Lapis Lazuli | Level 10

Thank you!
How to add code in this .sh file to save log and output?

 

also can I add "&"  in this  .sh file for batch submit?

Patrick
Opal | Level 21

@GeorgeSAS

SAS provides already a sas.sh file for this purpose out of the box under your application server context,

i.e: .../Config/Lev1/SASApp/sas.sh or .../Config/Lev1/SASApp/BatchServer/sas.sh

 

If you need to amend it then create your own sas_usermods.sh and include sas.sh with dot notation as a starting point.

 

Using sas.sh has the advantage that it will already invoke your batch environment with all the definitions for the chosen application server context (so executing all the .cfg and .autoexec for this context).

 

Tom
Super User Tom
Super User

SAS already knows how to save the LOG and LST for a program. If you run a program named "test1.sas" then it will automatically create a program named "test1.log" in the current directory to store the LOG and if you print anything to the listing output then it will also create a file name "test1.lst" to store that.  If you don't like those names you can add the -log and -print options to the command line to change them.

 

If you are running this command from CRON then there is not really much need to add & to the end of the command since it is already running in the background.  If you have two or three SAS programs you want fire up from the SAS script and you want them to run in parallel then you could add the &, but just remember that it means that any later steps you might want to have in there are not then guaranteed to run after the SAS program has finished.

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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