spss.DataStep Class (Python)
The DataStep
class implicitly
starts and ends a data step without the need to explicitly call StartDataStep
and EndDataStep
. In addition, it executes any pending transformations,
eliminating the need to check for them prior to starting a data step.
The DataStep
class is designed
to be used with the Python with
statement as shown in the following example.
Example
BEGIN PROGRAM.
import spss
with spss.DataStep():
datasetObj = spss.Dataset(name=None)
datasetObj.varlist.append('numvar')
datasetObj.varlist.append('strvar',1)
datasetObj.varlist['numvar'].label = 'Sample numeric variable'
datasetObj.varlist['strvar'].label = 'Sample string variable'
datasetObj.cases.append([1,'a'])
datasetObj.cases.append([2,'b'])
END PROGRAM.
-
with spss.DataStep():
initiates a block of code associated with a data step. The data step is implicitly started after executing any pending transformations. All code associated with the data step should reside in the block as shown here. When the block completes, the data step is implicitly ended.