?
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
Medium Priority
?
1,263 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
  • 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 41

Accepted Solution

by:
noci earned 2000 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 41

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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

839 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