Recode - Turn Off Missing Data Selection for Specific Values
Jump to navigation
Jump to search
Q Technical Reference
Q Technical Reference
Q Technical Reference > Setting Up Data > Creating New Variables
Q Technical Reference > Updating and Automation > Automation Online Library
Q Technical Reference > Updating and Automation > JavaScript > QScript > QScript Examples Library > QScript Online Library
This tool turns off the Missing Data setting for a particular value (or values) in every variable in your data set. It is generally useful if your data set has been created poorly, with missing data settings that have result in specific code values (e.g. 0) not showing up in your tables.
Usage
- Select Automate > Browse Online Library > Recode > Turn Off Missing Data Selection for Specific Values
- Type in the values which should be recoded, with multiple values separated with commas
- Choose which questions you wish to modify from the list presented.
How to apply this QScript
- Start typing the name of the QScript into the Search features and data box in the top right of the Q window.
- Click on the QScript when it appears in the QScripts and Rules section of the search results.
OR
- Select Automate > Browse Online Library.
- Select this QScript from the list.
Customizing the QScript
This QScript is written in JavaScript and can be customized by copying and modifying the JavaScript.
Customizing QScripts in Q4.11 and more recent versions
- Start typing the name of the QScript into the Search features and data box in the top right of the Q window.
- Hover your mouse over the QScript when it appears in the QScripts and Rules section of the search results.
- Press Edit a Copy (bottom-left corner of the preview).
- Modify the JavaScript (see QScripts for more detail on this).
- Either:
- Run the QScript, by pressing the blue triangle button.
- Save the QScript and run it at a later time, using Automate > Run QScript (Macro) from File.
Customizing QScripts in older versions
JavaScript
includeWeb("QScript Utility Functions");
includeWeb("QScript Selection Functions");
turnOffMissingValues()
function turnOffMissingValues() {
const web_mode = inDisplayr();
let selected_questions = [];
if (web_mode){
const user_selections = getAllUserSelections();
selected_questions = user_selections.selected_questions;
if (selected_questions.length == 0) {
log("Please select one or more variable sets under Data Sets and run this option again.");
return false;
}
} else {
// In Q just get all questions
project.dataFiles.forEach(function (data_file) {
selected_questions = selected_questions.concat(data_file.questions);
})
}
selected_questions = selected_questions.filter(function (q) { return q.questionType.indexOf("Text") == -1 && !q.isBanner});
if (selected_questions.length == 0) {
log("None of the " + (web_mode ? "selected variable sets" : "questions in your data") + " are appropriate.");
return false;
}
// Prompt the user to enter values to untick and make sure they
// give a sensible input.
let entered_values;
let got_valid_values = false;
let message = (web_mode ? "Enter value(s) which should be set to 'Include in analyses'" : "Enter value(s) to un-tick as Missing Data") + " (separate multiple values with commas):"
while (!got_valid_values) {
let input_string = prompt(message);
entered_values = input_string.split(",");
entered_values = entered_values.map(function (s) { return s.trim(); });
if (!entered_values.every(function (s) { return s == "NaN" || parseFloat(s) == s; })) {
alert("Enter numeric values or NaN only.");
} else {
got_valid_values = true;
}
}
// Convert to numeric
entered_values = entered_values.map(parseFloat);
selected_questions.forEach(function (q) {
let uniques = q.uniqueValues;
entered_values.forEach(function (value) {
// Check NaN values separately
if (isNaN(value) && uniques.some(isNaN)
|| uniques.indexOf(value) != -1) {
setIsMissingDataForVariablesInQuestion(q, value, false);
}
});
});
return true;
}
See also
- QScript for more general information about QScripts.
- QScript Examples Library for other examples.
- Online JavaScript Libraries for the libraries of functions that can be used when writing QScripts.
- QScript Reference for information about how QScript can manipulate the different elements of a project.
- 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.
Q Technical Reference
Q Technical Reference
Q Technical Reference > Setting Up Data > Creating New Variables
Q Technical Reference > Updating and Automation > Automation Online Library
Q Technical Reference > Updating and Automation > JavaScript > QScript > QScript Examples Library > QScript Online Library