Append Mode (Python)
This mode is used to append new cases to the active dataset. It
cannot be used to add new variables or read case data from the active
dataset. A dataset must contain at least one variable in order to
append cases to it, but it need not contain any cases. Append mode
is specified with spss.Cursor(accessType='a')
.
- The
CommitCase
method must be called for each case that is added. - The
EndChanges
method must be called before the cursor is closed. - Changes to the active dataset do not take effect until the cursor is closed.
- A numeric variable whose value is not specified (for a new case) is set to the system-missing value.
- A string variable whose value is not specified (for a new case) will have a blank value. The value will be valid unless you explicitly define the blank value to be missing for that variable.
- The
Cursor
methods SetValueChar and SetValueNumeric are used to set variable values for new cases.
Example
DATA LIST FREE /var1 (F) var2 (A2) var3 (F).
BEGIN DATA
11 ab 13
21 cd 23
31 ef 33
END DATA.
BEGIN PROGRAM.
import spss
cur=spss.Cursor(accessType='a')
ncases=cur.GetCaseCount()
newcases=2
for i in range(newcases):
cur.SetValueNumeric('var1',1+10*(ncases+i+1))
cur.SetValueNumeric('var3',3+10*(ncases+i+1))
cur.CommitCase()
cur.EndChanges()
cur.close()
END PROGRAM.
- An instance of the
Cursor
class in append mode is created and assigned to the variable cur. - The
SetValueNumeric
method is used to set the case values of var1 and var3 for two new cases. No value is specified for var2. TheCommitCase
method is called to commit the values for each case. - The
EndChanges
method is called to commit the new cases to the cursor.