spss.GetVariableFormat Function (Python)
GetVariableFormat(index). Returns a string containing the display format for the variable in the active dataset indicated by the index value. The argument is the index value. Index values represent position in the active dataset, starting with 0 for the first variable in file order.
- The character portion of the format string is always returned in all upper case.
- Each format string contains a numeric component after
the format name that indicates the defined width, and optionally,
the number of decimal positions for numeric formats. For example,
A4 is a string format with a maximum width of four bytes, and F8.2
is a standard numeric format with a display format of eight digits,
including two decimal positions and a decimal indicator. The supported format types are
listed in Variable Format Types (the type code
shown in the table does not apply to the
GetVariableFormatfunction).
Example
DATA LIST FREE
/numvar (F4) timevar1 (TIME5) stringvar (A2) timevar2 (TIME12.2).
BEGIN DATA
1 10:05 a 11:15:33.27
END DATA.
BEGIN PROGRAM.
import spss
#create a list of all formats and a list of time format variables
varcount=spss.GetVariableCount()
formatList=[]
timeVarList=[]
for i in range(varcount):
formatList.append(spss.GetVariableFormat(i))
#check to see if it's a time format
if spss.GetVariableFormat(i).find("TIME")==0:
timeVarList.append(spss.GetVariableName(i))
print formatList
print timeVarList
END PROGRAM.