• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4281
  • Last Modified:

How to run SAS program in UNIX Bash shell script?

I am trying to run .SAS program (test1.SAS) from Unix Bash shell script file. Please let me know what I am doing wrong in my Bash shell script or in my  .SAS program code.

Note: SAS dataset "dataset1.sas7bdat" does exist in the "testing" directory in Unix.

Unix Bash shell script

#script - tmp1.sh
export mydir
$sas test1

Open in new window


#filename test1.sas
libname lib "$mydir";
data lib.dataset2;
   set lib.dataset1;
   if _N_ < 10 then output;

Open in new window

Are there any other ways to run SAS programs (with SAS datasets) from Unix bash shell script?
  • 2
  • 2
1 Solution
Aloysius LowCommented:
you'll need to use the sysin parameter:
-sysin [filename.sas]

i can't remember if you can trigger a sas session by just sas, or if sas.sh is needed, but it should look like:
> sas -sysin test1.sas


> sas -sysin [full path]\test1.sas

there are other options you can include like -autoexec, -log etc
labradorchikAuthor Commented:
Thank you very much, lowaloysius!!

I will definitely try your way trigger SAS as well, but is it OK to reference  "mydir" logical as I did in the test1.SAS?
libname lib "$mydir";

Open in new window

Also, what if I want to reference a directory with a file (.SAS, .DAT, or .sas7bdat), would it logically work?
Thank you!
Aloysius LowCommented:
no it won't work... that is a UNIX variable which you are trying to use in a SAS session...

like i mentioned in my other answer, that's AFAIK... i'll be glad if a fellow expert proves me wrong on this...
labradorchikAuthor Commented:
Thank you!!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now