SetOneVarNameAndType Method (Python)
.SetOneVarNameAndType(varName,varType). Creates one new variable in the active dataset. The argument varName is a string that specifies the name of the new variable. The argument varType is an integer specifying the variable type of the new variable. You can create multiple variables with a single call using the SetVarNameAndType method.
- This method is only available in write mode.
- 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).
- Use of the
SetOneVarNameAndType
method requires theAllocNewVarsBuffer
method to allocate space for the variable.
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='w')
cur.AllocNewVarsBuffer(8)
cur.SetOneVarNameAndType('var4',0)
cur.SetVarFormat('var4',5,2,0)
cur.CommitDictionary()
for i in range(cur.GetCaseCount()):
cur.fetchone()
cur.SetValueNumeric('var4',4+10*(i+1))
cur.CommitCase()
cur.close()
END PROGRAM.