spssdictionary.GetDictionaryFromSPSS Function (R)
spssdictionary.GetDictionaryFromSPSS(variables). Retrieves variable dictionary information from the active dataset and stores it in an R data frame. The optional argument variables specifies the set of variables whose dictionary information will be retrieved. If the argument is omitted, dictionary information for all variables in the active dataset will be retrieved.
- The argument variables can be a character vector or list specifying the variable names,
a character string consisting of variable names separated by blanks,
or a numeric vector or list of integers specifying the index values
of the variables (index values represent position in the dataset,
starting with 0 for the first variable in file order). Variable names
must match case with the names as they exist in the active dataset's
dictionary.
When specifying variable names, you can use
TO
to indicate a range of variables. For example,variables=c("age TO income")
specifies age, income, and all variables between them in the active dataset's dictionary. You can also specify a range of values using index values, as invariables=c(2:4)
, which specifies the variables with index values 2 through 4. - Each column of the returned data frame contains dictionary
information for a single variable. The data frame has the following
row labels:
varName. The variable name.
varLabel. The variable label.
varType. The variable type; 0 for numeric variables, and an integer equal to the defined length for string variables.
varFormat. The display format of the variable, as a character string. 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.
varMeasurementLevel. The measurement level of the variable. Possible values are
"nominal"
,"ordinal"
,"scale"
, and"unknown"
. The value "unknown" occurs only for numeric variables prior to the first data pass when the measurement level has not been explicitly set, such as data read from an external source or newly created variables. The measurement level for string variables is always known.
Example
DATA LIST FREE /id (F4) gender (A1) training (F1).
VARIABLE LABELS id 'Employee ID'
/training 'Training Level'.
VARIABLE LEVEL id (SCALE)
/gender (NOMINAL)
/training (ORDINAL).
VALUE LABELS training 1 'Beginning' 2 'Intermediate' 3 'Advanced'
/gender 'f' 'Female' 'm' 'Male'.
BEGIN DATA
18 m 1
37 f 2
10 f 3
END DATA.
BEGIN PROGRAM R.
dict <- spssdictionary.GetDictionaryFromSPSS()
print(dict)
END PROGRAM.
Result
X1 X2 X3
varName id gender training
varLabel Employee ID Training Level
varType 0 1 0
varFormat F4 A1 F1
varMeasurementLevel scale nominal ordinal