Fixing the labels prior to setting a Pick Any question

From Q
Jump to navigation Jump to search

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