Solved

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

Posted on 2012-03-22
5
1,149 Views
Last Modified: 2012-03-26
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_loop: 
  read/end_of_file=endit indat var1
  var2=f$extract(0,2,var1)
   if f$search("mydir1:file2.s''var2'") .nes. " " 
    then  
    del mydir1:file2.s'var2';* 
   endif
endit:
 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!!
0
Comment
Question by:labradorchik
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 37755994
> .. extract a particular variable ..
could you please give an example what you want to extract

maybe this helps:
  grep  " mydir1" myfile.dat
0
 
LVL 40

Accepted Solution

by:
noci earned 500 total points
ID: 37760232
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...
do
  var2=$(echo ${var1} | cut -b1-2 )          # f$extract
   if -f  mydir1/file2.s${var2}             # f$search
   then
       rm mydir1/file2.s${var2}
   fi
done
rm myfile.dat

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

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

Author Comment

by:labradorchik
ID: 37767366
noci, thank you very much for your help!!!
I probably will use your example #2. Looks very different from the VAX DCL code.
0
 
LVL 40

Expert Comment

by:noci
ID: 37768463
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.
0
 

Author Comment

by:labradorchik
ID: 37768524
Thank you for your comments!!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Starting up a Project

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