Fixing the labels prior to setting a Pick Any question
In some cases where data files have not been created according to the SPSS Data File Specifications, the variable labels that Q expects to find have instead been placed in the Value Attributes of a variable, as the label for the value '1'. This type of problem will cause the labels on tables to be incorrect once the variables have been combined into a Pick Any question.
This function takes an array of variables that you wish to combine as a Pick Any question and moves the label from the Value Attributes to the Variable Label. It replaces the existing labels for '0' and '1' to 'Not Selected' and 'Selected', respectively. An array containing references to all of the variables of a question can often be obtained using the function getVariablesByName.
function fixPickAnyVariableLabels(vars) {
for (var kk = 0; kk < vars.length; kk++){
vars[kk].label = vars[kk].valueAttributes.getLabel(1);
vars[kk].valueAttributes.setLabel(0,'Not Selected');
vars[kk].valueAttributes.setLabel(1,'Selected');
}
}
See also
- QScript for an explanation of how to run this code.
- QScript Examples Library for other examples.
- QScript Reference for technical information.
- JavaScript for information about the JavaScript programming language.
- Table JavaScript and Plot JavaScript for tools for using JavaScript to modify the appearance of tables and charts.
- JavaScript Variables for detail on how to create new variables in the Variables and Questions tab using JavaScript.