spssdictionary.GetVariableAttributes Function (R)
spssdictionary.GetVariableAttributes(variable,attrName). Returns the value(s) for the specified
variable and attribute in the active dataset. The argument variable can be a character string specifying
the variable name or an integer specifying the index value of the
variable (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.
The argument attrName is a character
string that specifies the name of the attribute--for instance, a name
returned by GetVariableAttributeNames
.
- In the case that the specified attribute is an array, the returned value is a vector containing the attribute values.
Example
#Create a list of variables with a specified attribute and value
varList <- vector()
dict <- spssdictionary.GetDictionaryFromSPSS()
varnames <- dict["varName",]
attr <- "demographicvartypes"
val <- "2"
for (name in varnames){
attrNames <- spssdictionary.GetVariableAttributeNames(name)
if(any(attr==attrNames)){
if(any(val==spssdictionary.GetVariableAttributes(name,attr)))
varList <- c(varList,name)
}
}
{if (length(varList) > 0){
cat(paste("Variables with attribute value ",val,
" for attribute ",attr,":\n"))
cat(varList,sep="\n")}
else
cat(paste("No variables have the attribute value ",val,
" for attribute ",attr))
}