Variable Class (Python)
The Variable
class allows
you to get and set the properties of a variable. Instances of the Variable
class for each variable in the
associated dataset are generated when the VariableList
class is instantiated. In addition, the append
and insert
methods of a VariableList
object
create associated instances of the Variable
class for appended and inserted variables. Specific variables can
be accessed by name or index (index values represent position in the
dataset, starting with 0 for the first variable in file order).
datasetObj = spss.Dataset('data1')
# Create a Variable object, specifying the variable by name
varObj = datasetObj.varlist['bdate']
# Create a Variable object, specifying the variable by index
varObj = datasetObj.varlist[3]
Note:
An instance of the Variable
class
can only be created within a data step, and cannot be used outside
of the data step in which it was created. Data steps are initiated
with the spss.StartDataStep
function.