spss.GetVarAttributes Function (Python)
spss.GetVarAttributes(index,attrName). Returns the attribute values, as a tuple,
for the specified attribute of the variable in the active dataset
indicated by the index value. The argument index is the index value. Index values represent
position in the active dataset, starting with 0 for the first variable
in file order. The argument attrName is a string that specifies the name of the attribute--for instance,
a name returned by GetVarAttributeNames
.
Example
#Create a list of variables whose attribute array contains
#a specified value
import spss
varList=[]
attrName='demographicvartypes'
attrVal='2'
for i in range(spss.GetVariableCount()):
try:
if(attrVal in spss.GetVarAttributes(i,attrName)):
varList.append(spss.GetVariableName(i))
except:
pass
if varList:
print("Variables with attribute value " + attrVal + \
" for attribute " + attrName + ":")
print('\n'.join(varList))
else:
print("No variables have the attribute value " + attrVal + \
" for attribute " + attrName)