<Below this line, add a link to the exact exercise that you are stuck at.>
(Not a codeacademy exercise)
<In what way does your code behave incorrectly? Include ALL error messages.>
An SPSS syntax file calls the python program, and it returns an “Error Computing Case” line for each case.
<What do you expect to happen instead?>
```pythonReplace this line with your code. Do not remove the backticks that are above or beneath this line.
import spss
import sys
def getNameMatchVariables(lnam1=“LNAM_A”,lnam2=“LNAM”,fnam1=“FNAM_A”,fnam2=“FNAM”):
if “R:\python” in sys.path:
print “R:\python Already A Recognized Directory”
else:
sys.path.append(“R:\python”)
print “R:\Python added as a Directory”
import soundex
import levin
import spss
varnames =
varcount = spss.GetVariableCount()
for i in xrange(varcount):
varnames.append(spss.GetVariableName(i))
lnam1index = varnames.index(lnam1)
lnam2index = varnames.index(lnam2)
fnam1index = varnames.index(fnam1)
fnam2index = varnames.index(fnam2)
datacur = spss.Cursor(accessType = ‘w’)
datacur.SetVarNameAndType([‘JAWAL’,‘DICEL’,‘LENL’,‘JAWAF’,‘DICEF’,‘LENF’,‘L1SOUND’,‘L2SOUND’,‘F1SOUND’,‘F2SOUND’],[0,0,0,0,0,0,4,4,4,4])
datacur.CommitDictionary()
for i in range(datacur.GetCaseCount()):
casecursor = datacur.fetchone()
try:
str1 = levin.cleanString(casecursor[lnam1index])
str2 = levin.cleanString(casecursor[lnam2index])
str3 = levin.cleanString(casecursor[fnam1index])
str4 = levin.cleanString(casecursor[fnam2index])
datacur.SetValueNumeric(‘JAWAL’,100levin.getJaWasteve(str1,str2))
datacur.SetValueNumeric(‘DICEL’,100levin.getDice(str1,str2))
datacur.SetValueNumeric(‘LENL’,100levin.getLenWt(str1,str2))
datacur.SetValueNumeric(‘JAWAF’,100levin.getJaWasteve(str3,str4))
datacur.SetValueNumeric(‘DICEF’,100levin.getDice(str3,str4))
datacur.SetValueNumeric(‘LENF’,100levin.getLenWt(str3,str4))
datacur.SetValueChar(‘F1SOUND’,soundex.get_soundex(casecursor[fnam2index]))
datacur.SetValueChar(‘L1SOUND’,soundex.get_soundex(casecursor[lnam2index]))
datacur.SetValueChar(‘F2SOUND’,soundex.get_soundex(casecursor[fnam1index]))
datacur.SetValueChar(‘L2SOUND’,soundex.get_soundex(casecursor[lnam1index]))
datacur.CommitCase()
except:
print “Error Computing Case”
try:
print casecursor[varnames.index(“CASE”)]
except:
print “CASE variable not in file”
datacur.close()
def getMasterNYSID():
if “R:\python” in sys.path:
print “R:\python Already A Recognized Directory”
else:
sys.path.append(“R:\python”)
print “R:\Python added as a Directory”
varnames =
varcount = spss.GetVariableCount()
for i in xrange(varcount):
varnames.append(spss.GetVariableName(i))
datacur = spss.Cursor(accessType = ‘w’)
datacur.SetVarNameAndType([‘NYSIDM’],[8])
datacur.CommitDictionary()
nysidlist = [‘NYSIDR’,‘NYSIDN’,‘NYSIDN2’,‘NYSIDN3’,‘NYSIDN4’,‘NYSIDN5’]
nysiddict = {}
exclude = [’’,’ ‘,’ ‘,’ ‘,’ ',None,‘0000000’,'0000000 ']
for n in nysidlist:
nysiddict[n]=varnames.index(n)
x = 0
for i in range(datacur.GetCaseCount()):
casecursor = datacur.fetchone()
x=x+1
try:
nysids =
for n in nysiddict:
if casecursor[nysiddict[n]] not in exclude:
nysids.append(casecursor[nysiddict[n]])
nysids.sort()
datacur.SetValueChar(‘NYSIDM’,nysids[0])
datacur.CommitCase()
except:
print "ERROR " , nysids, n,x
datacur.close()
<do not remove the three backticks above>