append Method (Python)

.append(name,type). Appends a new variable to the associated dataset and appends a corresponding Variable object to the associated VariableList instance. The argument name specifies the variable name. The argument type is optional and specifies the variable type--numeric or string. The default is numeric.

  • Numeric variables are specified by a value of 0 for the variable type. String variables are specified with a type equal to the defined length of the string (maximum of 32767).
  • The properties of the new variable are set using the Variable object created by the append method. See the topic Variable Class (Python) for more information.

Example

DATA LIST FREE/numvar (F2).
BEGIN DATA.
1
END DATA.
BEGIN PROGRAM.
import spss
spss.StartDataStep()
datasetObj = spss.Dataset()
# Append a string variable of length 1 to the active dataset
datasetObj.varlist.append('strvar',1)
spss.EndDataStep()
END PROGRAM.