[Tutor] ksh and SAS questions

adeline_j_wilcox@ccMail.Census.GOV adeline_j_wilcox@ccMail.Census.GOV
Wed, 12 May 1999 18:05:49 -0400


Using a script named recheck.py, I call a ksh script named 
setcm.ksh. That script exports some shell variables. I would like to
substitute the value of one shell variable in particular, named CATI,
for the value 199904 in lines 14, 23 and 24. Please note that
I want to pass the value of this shell variable to a SAS program with the
SYSPARM option in line 23.
Can anyone tell me how to get ksh, Python and SAS working together here?
I need to get the value of the shell variable into Python and pass it
to SAS as well as make other use of its value.
BTW, this script is in production, at least
until the task is passed to other programmers within a few months.

I have neither C programming nor OOP experience. Also very new to Python.
Have done a little reading of Lutz 1996 Programming Python. Reference
to the Python documentation on the Web could be helpful.
Adeline Wilcox
       1        #!/usr/local/bin/python
       2        #PROGRAM: recheck.py
       3        #FUNCTION: execute Barbara's RECHECK program
       4        #INPUTS: rofr.txt
       5        #OUTPUTS: rofr.sas, ccMail message
       6        #CALLS TO: Python os, sys, and string modules, 
     recheck.sas
       7        #SPECIAL NOTES: Have not yet figured out how to 
     automate input of the royyyymm file
       8        #AUTHOR: Adeline Wilcox         DATE: 05Apr99
       9        #Written with the assistance of Andrew Kuchling and 
     especially Tim Peters
      10        #UPDATED:                       DATE: 
      11        import os, sys 
      12        os.system('/op/ctl/prod/scripts/setcm.ksh')
      13        import string
      14        sys.stdin = open('/op/ctl/prod/data/ro199904.txt','r')
      15        lines = sys.stdin.readlines()
      16        for i in range(len(lines)):
      17            line = lines[i]
      18            lines[i] = "'" + string.rstrip(line) + "'"
      19            sys.stdout= open('/op/ctl/prod/data/rofr.sas','w')
      20            print "if rofr in (" + string.join(lines, ", ") + 
     ") then output;"
      21            #if I dont close the file, SAS does not get quotes 
     around last value of rofr
      22            sys.stdout.close()
      23        os.system("$SASDIR/sas /op/ctl/prod/prgms/recheck.sas 
     -sysparm 199904 -log /op/ctl/prod/logs/recheck.log.199904")
      24        os.system("mailx -s '199904 for you' 
     Adeline.J.Wilcox@ccmail.census.gov < rc199904.txt")