Skip to content

Recode Data in a Wrangle

“The Recode node allows you to change the values of a selected variable or variables.” Use it to group ages into bands, turn scores into categories, tidy up inconsistent values, or fill in blanks.

Each Recode Function takes one source variable and a set of rules, and writes the result to a new variable or over an existing one. Add as many functions to a Recode step as you need.


Data Wrangler has two Recodes. They share a name but work differently:

Recode in Variable ViewRecode step in a wrangle (this page)
Where you build itVariable View of a data storeThe wrangle editor
Where the result goesA new variable, or one you added, in the same data storeAny field the wrangle writes, in a new or existing data store
When it runsOnce. Run it again by hand when the source changes.Every time the wrangle runs, including on a schedule
RulesEqual, In, comparisons, Between and more, giving codes and labels, numbers or textSingle Value, Value Range or Missing Values
Records no rule matchesGet the Else result you chooseAre left blank, unless you add a catch-all
PreviewLive preview on a sample of your recordsNone. Check the output after the wrangle runs.
CodeframeA Categorical Recode creates oneNone. Add it to the output data store yourself.

  1. Add the Recode step - Drag Recode from MICROSERVICES onto the canvas, connect it between your Reader and Writer, then click it.
  2. Click Add Recode Function - On the Function tab. The Add New Recode Function dialog opens.
  3. Choose the source - “Please select your Source Variable”. Drag one variable into Selected Fields, then click NEXT. Multi-response variables can’t be recoded.
  4. Choose where the result goes - Under “Recode to:”, choose:
    • New Field (the default): click Add New Variable, enter a Variable Name, Variable Label and Variable Type, and click Save.
    • Existing Field (overwrite): choose the variable to write over. It can be the source variable itself.
  5. Add your rules - See Write the rules.
  6. Click NEXT - The function appears in the Recode Functions table.

Remember to add a new variable to the Writer’s Output Fields.


Each rule answers three questions:

QuestionOptions
”How do you want to recode?” (the old value)Single Value, Value Range (Min Value and Max Value), or Missing Values
”What is your desired result?” (the new value)Single Value, Existing Value (keep it as it was), or Missing Values (blank)
“What about records that don’t match?”Ignore (the default), Existing Value, Single Value or Missing Values

Set the three answers, then click ADD. The rule appears in Recode Rules. Add more rules the same way.

To turn a 0–10 score into 1 = Detractor, 2 = Passive, 3 = Promoter in a new field:

Old valueNew valueRecords that don’t match
Value Range 0 to 6Single Value 1Ignore
Value Range 7 to 8Single Value 2Ignore
Value Range 9 to 10Single Value 3Ignore
  • Rules are checked in order, and only the first rule that gives a result is used.
  • A rule gives a result when the value matches it, or when the value doesn’t match and its “don’t match” answer is anything other than Ignore.
  • Ranges include both ends, so 0 to 6 includes 0 and 6. You can leave Min Value or Max Value blank for an open-ended range.
  • Text is matched ignoring capitals.
  • Missing Values matches records with no value at all.
  • If no rule gives a result, the destination is left blank.

  • Change the rules: click the edit icon on the function. In Edit Recode Function, delete rules and add new ones, then click SAVE. Rules can’t be edited in place, and you can’t change the source or destination here.
  • Remove a function: click the delete icon and confirm.

To use a different source or destination, delete the function and add a new one.

Use the Row Filter tab to recode only some records. Records outside the filter are left as they are. The filter applies to every function in the step.


Can I recode several variables at once?

Add one Recode Function per variable. A Recode step can hold as many functions as you need.

Why did my later rules have no effect?

An earlier rule probably has a “don’t match” answer other than Ignore, so it gave a result for every record first. See How rules are applied.

Can I recode from a lookup table?

Not at the moment. The Reference Table option isn’t available.

Does Recode add a codeframe to the new variable?

No. To label your new codes, add a codeframe to the variable in the output data store. See Codeframes.


“Please check your configuration and try again.” Part of the rule is empty.

  1. Fill in the values - Enter a Single Value wherever you’ve chosen it, and at least one of Min Value or Max Value for a range.

”Variable with this type is not allowed. Please pick another variable.”

Section titled “”Variable with this type is not allowed. Please pick another variable.””

You picked a multi-response variable.

  1. Pick another variable - Recode a single-value variable instead.

No rule gave a result for those records.

  1. Check your rules - Make sure they cover every value, including blanks (Missing Values).
  2. Add a catch-all - Set the last rule’s “don’t match” answer to Existing Value or a Single Value.