How to define SAS datatset (with proper directories) in Unix Bash shell script?

I am trying to define a SAS dataset directly from Unix bash shell script. The way that I am doing it in my Bash shell script is not working. I used to run SAS programs on VAX DCL code, so I am not very familiar with Unix Bash shell script. Please let me know what I am doing wrong?  

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
mydata=/2011/march/tuesday/testing/dataset2.sas7bdat
export mydir
export mydata
sas=/products/SAS/SASFoundation/9.2/sas
$sas test1
exit

Open in new window


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

Open in new window


I already tested my way and it's not working, so I am looking for some kind of another way of directly referencing a SAS dataset in the Unix Bash shell script.
Thank you!
labradorchikAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Aloysius LowCommented:
can't be done AFAIK

is there any constraint that you have that you must do it this way? could you have the information stored in another SAS dataset/code and execute that file in the SAS program which will instantiate variables?
0
labradorchikAuthor Commented:

Thank you, lowaloysius!

I don't have to use this way, I can use any way that works, :) - I am just trying to understand what can be done and what can't be done in Unix bash shell script vs VAX DCL code (.COM code vs bash shell script).  Can I reference a SAS dataset within/directly from the Unix bash shell script or I have to/must run a SAS program with that SAS dataset through Bash script?

In DCL I usually used to reference/used logicals or just hardcoded directories with filenames like .sas7bdat, .LOG, .LIS, .SAS, or .DAT and that was very helpful. How I understand Unix bash shell script doesn't use logicals the same way as VAX DCL code. So far I figured out how I can use Unix logicals for referencing directories, but I am not sure how can I use Unix logicals for directories together with filenames?

Please also see another question that I have at this link:  
http://www.experts-exchange.com/OS/Unix/Q_27640685.html

Thank you!
0
labradorchikAuthor Commented:
lowaloysius,
in your question "could you have the information stored in another SAS dataset/code and execute that file in the SAS program which will instantiate variables?" by variables do you mean SAS dataset variables or logicals (with full directory path and file names like .LIS, .DAT, or .sas7bdat) that can be used in SAS program?

Before, I used the same logicals for both (VAX DCL code and SAS program) when referencing those logicals to full directory path and files like .LIS, .DAT, or .sas7bdat.  Now, since how I understand I can't use logicals for directories with files in Unix bash shell script, to me it appears that I can not use the same method in Unix bash shell script as I was using in VAX DCL code.
Please correct me if I am wrong or please explain how may I reference directories and file names like .LIS, .DAT, or .sas7bdat  in the best way in Unix bash shell script?

Note: I need this in the Unix bash shell script mainly for opening a file, writing to a file, or simply just deleting a file after Unix bash shell script finish running my .SAS programs.
0
Powerful Yet Easy-to-Use Network Monitoring

Identify excessive bandwidth utilization or unexpected application traffic with SolarWinds Bandwidth Analyzer Pack.

Aloysius LowCommented:
you'll need to do the initialization within a SAS code, either in the main, or in another SAS code which gets called by the main SAS code.

i haven't done VAX DCL before, so i'm not able to comment much on what is possible or not.

in fact, based on your description, it appears that you would like to have the initialization done once only, and to use it in both the SAS code as well as the UNIX batch command, which is not possible.

however, if your requirement is to open a file, writing to a file or deleting the file afte rthe UNIX bash shell executes the .SAS and you would like the initialization to be done only once, i suggest using the X command within the SAS code.

this X command can execute any UNIX/DOS command as if you are executing it from the command line.

if going by this, all your UNIX bash script needs to do is to execute the SAS code.

e.g.

#SAS CODE#
/*variable initialization*/
%let directory=/temp/;
%let file=mydata;

/*do something*/
libname temp "&directory";
data temp."&mydata";
  x=1;
run;

/*cleaning up*/
x "rm &directory.&file..sas7bdat";


#shell script#
sas -sysin [your sas code]

not sure if this is what you wanted...
0
labradorchikAuthor Commented:
lowaloysius, thank you very much for your comments!
Your code for SAS programs will definitely work for the "delete" purposes, but this is not the only function I am looking to implement in the Unix bash shell script after running my SAS programs.  I also need to open or append and write into files like .LOG, .LIS, .DAT, or .sas7bdat in Unix bach shell script.  
From your knowledge in Unix, do you know if some of these files like .LOG, .LIS, .DAT, or .sas7bdat can't be opened or appended in the Unix bash shell script?
May I do the same functions in the Unix bash shell script as I did in Vax DCL?
For example: I usually open .LOG files to automatically find errors in my .SAS programs, then open .LIS file to write some messages about a particular error, which resulted from the .SAS program after the run. Also, if I run a few .SAS programs within the DCL code then I append all .LOGs with a message for every .SAS program like "Module1 Successfully Processed" into one final .LIS file. All of these functions were done directly from the DCL code, so I think there should be a way to do exactly the same in the Unix bash shell script.    

Any of your comments will be greatly appreciated!
0
Aloysius LowCommented:
in unix, you can append text files together without any issues, or to write a value out to a file e.g.

to append fileA.txt and fileB.txt into fileC.txt, where fileC is a new file:
more fileA.txt > fileC.txt
more fileB,txt >> fileC.txt

if fileC is an existing file and you want to continue to append fileA and fileB into fileC, just change the first line to use >> instead of >
(>> appends into the file, creates one if not present, > creates a new file and writes in, overwriting the existing file if present)

similar concept can be used to write a message into a text file:
echo "hello" > fileC.txt

sas datasets (sas7bdat) would be tricky, as it will require a SAS code to do the appending

as for opening a log file to check for a certain message, you can actually have a UNIX shell script which contains the necessary logic... i don't have a copy, but i've seen it somewhere before on my project implementation sites... you can use a combination of UNIX shell commands to scan for a particular text and based on the result, write a message into a text file. the input to this 'utility' script would be the log file name, which can be executed by SAS using the X command as usual... if you need the exact code for the script, I guess you'll need to open another question for that, specifically in the UNIX thread :)

hope i have managed to addressed most of your questions and/or doubts

p.s. i have not touched UNIX for quite some time, so the commands above might not work correctly, although the idea/concept is there
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
labradorchikAuthor Commented:
This is exactly what I needed!!!!  Great examples too! I will open a few other different Unix/SAS questions later on today...
Thank you VERY MUCH!! :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.