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!
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
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?
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).
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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.