How to open SAS dataset in Unix bash shell script and extract a certain variable from that dataset?

I am looking for an example of how to open .DAT in the Unix bash shell script and then extract a particular variable from that .DAT file into a different file.

Please note: this is how this function was done in VAX DCL code

open/read indat myfile.dat
  read/end_of_file=endit indat var1
   if f$search("mydir1:file2.s''var2'") .nes. " " 
    del mydir1:file2.s'var2';* 
 close indat
 del myfile.dat;*

Open in new window

Any examples or comments on how this might be done in the Unix bash shell script will be greatly appreciated!!
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

> .. extract a particular variable ..
could you please give an example what you want to extract

maybe this helps:
  grep  " mydir1" myfile.dat
nociSoftware EngineerCommented:
This would be roughly equivalent code, assuming you use subdirectories in stead of logicals.
Environment variables like var can be used to (see example 2)

cat  myfile.dat | while read var1           # read...
  var2=$(echo ${var1} | cut -b1-2 )          # f$extract
   if -f  mydir1/file2.s${var2}             # f$search
       rm mydir1/file2.s${var2}
rm myfile.dat

#Example 2
cat  myfile.dat | while read var1           # read...
  var2=$(echo ${var1} | cut -b1-2 )          # f$extract
   if -f  ${MYDIR}/file2.s${var2}             # f$search
       rm ${MYDIR}/file2.s${var2}
rm myfile.dat

for prefix in $( cut -b1-2 <myfile.dat)
   rm mydir1/file2.s${prefix}

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:
noci, thank you very much for your help!!!
I probably will use your example #2. Looks very different from the VAX DCL code.
nociSoftware EngineerCommented:
example1 & 2 stay relatevely close to the DCL original...
example 3 is most unix like...
And you're right bash shell doesn't look like DCL.
labradorchikAuthor Commented:
Thank you for your comments!!
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.