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,132 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

Industry Leaders: 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

Suggested Solutions

Title # Comments Views Activity
Visual Studio hangs on running project 6 61
$_GET call between URL 3 43
Building a glossary into your website 9 22
Dump data from mysql to xls php 10 24
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

733 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