Solved

How to run SAS program in UNIX Bash shell script?

Posted on 2012-03-20
4
3,018 Views
Last Modified: 2012-03-21
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
#!/bin/bash
mydir=/2011/march/tuesday/testing
export mydir
sas=/products/SAS/SASFoundation/9.2/sas
$sas test1
exit

Open in new window



SAS

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

Open in new window


Are there any other ways to run SAS programs (with SAS datasets) from Unix bash shell script?
0
Comment
Question by:labradorchik
  • 2
  • 2
4 Comments
 
LVL 14

Accepted Solution

by:
Aloysius Low earned 500 total points
ID: 37745647
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

or

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

there are other options you can include like -autoexec, -log etc
0
 

Author Comment

by:labradorchik
ID: 37747592
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!
0
 
LVL 14

Expert Comment

by:Aloysius Low
ID: 37747859
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...
0
 

Author Closing Comment

by:labradorchik
ID: 37747940
Thank you!!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is about my first experience with programming Arduino.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now