Recode Variables in Variable View
Got a 0–10 score that you’d rather see as Detractors, Passives and Promoters? Or ages you’d like in bands? Recode builds a new variable from an existing one, right in Variable View. You write a few rules, watch a live preview of how your records land, and click DONE.
There’s no wrangle to build and nothing to connect. The new variable sits alongside the original, ready for Data Explorer, dashboards and everything else that reads the data store.
Understanding Recode
Section titled “Understanding Recode”What you can create
Section titled “What you can create”Every Recode has one source variable and creates one output. You choose the kind of output with Variable Type:
| Variable Type | What it’s for | What it creates |
|---|---|---|
| Categorical (the default) | “Countable, filterable, and crosstabable output with labelled codes.” For example, 1 = Detractor, 2 = Passive, 3 = Promoter. | An Integer variable. Your codes and labels become its codeframe. |
| Numeric | ”Averageable score output with a Scale measure and numeric values.” For example, turning answers into points you can average. | A Number variable |
| Text | ”Templated text output with optional interpolation from eligible Data Store variables.” For example, a readable label built from other variables. | A Text variable |
Which variables you can recode
Section titled “Which variables you can recode”The source can be a Text, Long Text, Integer, Number or Boolean variable. It can’t be:
- a Date, Date Time, Time, Guid or Multi-Response variable
- a variable whose personal information is set to Mask, Mask + retention or Wipe
Recodes work on draft and published data stores, and on survey data stores. In a survey data store, you can recode the survey’s variables, but you can’t overwrite source survey variables.
How a Recode runs
Section titled “How a Recode runs”A Recode runs once, when you click DONE. It doesn’t run again by itself when new records arrive or the source changes.
If the source variable changes after a Recode has run, the output variable is tagged STALE in Variable View: “The source changed after this action ran. Reopen it to run again.” See Reopen or run a Recode again.
Start a Recode
Section titled “Start a Recode”You can start from the toolbar or from the variable itself.
- Open Variable View - On the data store page, click the Variable View tab.
- Click Add Variable - The Add Variable dialog asks you to “Choose how you’d like to create your new variable”, with a search box above the options.
- Choose Recode - Click the Recode card, “Create a new variable by transforming values from an existing variable.”, then click SELECT. The Recode window opens full screen.
Or, in Variable View, click the Recode Variable icon on the row of the variable you want to recode. The Recode window opens with that variable already chosen as the source.
If the Recode card is locked, the data store has nothing you can recode: “Recode requires at least one eligible source variable in this data store.” See Which variables you can recode.
The Recode window has two steps, Source & output and Build rules. Use NEXT and BACK to move between them. NEXT stays disabled until the current step is complete.
Step 1: Choose the source and output
Section titled “Step 1: Choose the source and output”Choose the source
Section titled “Choose the source”Under Choose Your Inputs, drag a variable from Available Variables into Selected Variables. A Recode takes one source variable.
Data Wrangler loads a sample of up to 1,000 records from the source, which it uses to preview your rules. You’ll see “Loading a stable source sample…” while it loads. The sample doesn’t use any Data View filters.
Define the output
Section titled “Define the output”Under Define the Output, choose a Destination: “Where should we save the recoded result?”
- New Variable (the default): “Create a new variable for the results”.
- Overwrite Existing: “Write the results over an existing variable”. See Overwrite an existing variable.
For a new variable, check or change these fields. Data Wrangler fills them in for you from the source:
| Field | What to enter |
|---|---|
| New Variable Name | The system name. It’s filled in for you from the source, for example nps_band for a Categorical Recode of nps. It must start with a letter and use only letters, digits and underscores, up to 100 characters. |
| Variable Label | The friendly name people see. It’s suggested from the source’s label (or its name, if it has no label) plus “band”, “score” or “label”, for example “AGE band”. Change it to whatever reads best. |
| Variable Type | Categorical, Numeric or Text. See What you can create. |
The suggested name ends in _band for Categorical, _score for Numeric and _label for Text, and the suggested label ends in the same word. If the name is already taken, you’ll see “This name already exists. Choose a numbered alternative:” with some suggestions. Click one to use it, or type your own.
You can switch Variable Type later. If you’ve already added rules, you’ll be asked “Switch this draft to … output?” Click Switch or Cancel. Each type keeps its own rules, so switching back brings yours back.
Click NEXT.
Overwrite an existing variable
Section titled “Overwrite an existing variable”Choose Overwrite Existing to put the results into a variable you already have. Choose it from Overwrite Target, then type its name in Type the target name to confirm.
You can only overwrite a variable that:
- was added in Data Wrangler, not by a survey
- isn’t the primary key, a multi-response variable or one of its child variables
- isn’t set to Mask, Mask + retention or Wipe
- matches the output type: Integer for Categorical, Number for Numeric, or Text for Text
If nothing qualifies, Overwrite Existing is unavailable.
Step 2: Build the rules
Section titled “Step 2: Build the rules”On the Rule Builder tab, each rule says “if the source is this, the output is that”. Rules are checked from the top down, and the first rule a record matches wins. Records that match no rule fall to Else.
- Click Add Rule - Until you add one, the tab shows “No rules yet” and “Add your first rule to start mapping values to codes.” Click Add Rule and Rule 1 appears.
- Set the condition - Under IF, choose an Operator and enter the Value (or From and To for Between, or Values for In). The Variable is always your source.
- Set the result - Under THEN CODE, enter what matching records get. See Results by type.
- Add more rules - Click Add Rule for each group you need. Use Move rule up and Move rule down to change the order, and Delete rule to remove one.
- Check Else - Decide what happens to everything else. See Else: everything that doesn’t match.
Each rule shows how many sample records it catches, for example “312 rows · 31.2%”.
Conditions
Section titled “Conditions”Each rule has one condition. The operators depend on the source:
| Operator | Matches | Available for |
|---|---|---|
| Equal / Not Equal | One value, or everything except it | All sources |
| In | Any of several Values. Tick Include system-missing in this bucket to include blanks too. | All sources |
| Is Missing / Is Not Missing | Blank values, or anything that isn’t blank | All sources |
| Less Than, Less Than or Equal, Greater Than, Greater Than or Equal | Values below or above a number | Integer and Number sources |
| Between | Values from From to To, including both | Integer and Number sources |
Results by type
Section titled “Results by type”| Variable Type | Fields under THEN CODE |
|---|---|
| Categorical | Code (a whole number) and Label |
| Numeric | Value and an optional Description |
| Text | Text template: the text to write. Type @ to pick another variable and include its value, for example @region. |
In a Categorical Recode, give the same code the same label every time. If two rules share a code, their labels must match.
Else: everything that doesn’t match
Section titled “Else: everything that doesn’t match”The Else row, “Else — all other rows”, is always last. It catches “Rows matching no rule above, or with a null in any input”.
By default, Else gives a blank: NULL for Categorical and Numeric, or an empty string for Text. To give these records a result instead, click Use a code, Use a value or Use text and fill it in. Click Use NULL to go back to a blank.
When Else is left on NULL, the Codeframe panel reminds you: “The Else rule outputs NULL, so it has no code-frame entry.”
For a Numeric Recode from a number, you can also keep each record’s original value, but only on the Syntax tab. See ELSE.
Check the preview
Section titled “Check the preview”As you build, three panels update from the sample:
| Panel | What it shows |
|---|---|
| Codeframe | For Categorical Recodes, each code and its label: “One label per distinct code” |
| Coverage | How the sample records are spread across your rules and Else |
| Live Preview | Sample records side by side: the source value and the result it gets |
If records match more than one rule, you’ll see Overlapping coverage. That’s a warning, not an error: those records get the first rule they match. Reorder your rules if the wrong one is winning.
Example: NPS groups
Section titled “Example: NPS groups”To turn a 0–10 Integer score called nps into NPS groups:
-
Choose the source and output - Drag
npsinto Selected Variables. Keep New Variable and Categorical, and set Variable Label to “NPS group”. -
Add the rules - On Build rules, add these three rules:
Rule Operator Value Code Label Rule 1 Between 0 to 6 1 Detractor Rule 2 Between 7 to 8 2 Passive Rule 3 Between 9 to 10 3 Promoter -
Leave Else on NULL - Anyone without a score stays blank.
-
Click DONE - The new variable is created and the Recode starts running.
Run the Recode
Section titled “Run the Recode”- Click DONE - You’ll see “Creating Recode”, then “Recode queued”: “Recode saved and queued. It will continue running in the background.”
- Watch for RUNNING - The output variable appears in Variable View straight away, tagged RUNNING: “This action is executing.” You can carry on working, or leave the page.
- Check it finished - When it’s done, a Recode complete message tells you, for example, “Created nps_band. Variable View has been refreshed.” Click OK.
A quick Recode can finish before you see the first two messages or the RUNNING tag. That’s fine: the Recode complete message is the one that counts.
DONE stays disabled until the rules are complete. A Recode needs at least one rule, so you can’t send everything to Else. A list headed “Complete the required fields to finish:” tells you what’s missing.
If you leave and come back while a Recode is running, Variable View picks it up again and shows RUNNING until it finishes.
Reopen or run a Recode again
Section titled “Reopen or run a Recode again”Reopen a Recode to change its rules or its Variable Label, or to run it again after the source has changed (it’s tagged STALE).
- Open the Recode - Click the Reopen Recode / Run again icon on the output variable’s row, or use Reopen in Manage Actions. The Reopen Recode window opens.
- Make your changes - You can change the Variable Label and the rules. The source, the Variable Type and the destination are locked.
- Click RUN AGAIN - You’ll see “Running Recode again” (“Saving the existing definition and creating a new execution.”), then “Recode queued again” (“Recode queued again. It will continue running in the background.”). The output is recalculated for every record, and you’ll see the same Recode complete message as for the first run. The STALE tag clears.
To recode from a different source, or into a different type or variable, start a new Recode.
Manage Actions
Section titled “Manage Actions”Manage Actions lists every Recode and Compute in the data store and every time one has run. Click Manage Actions in the Variable View toolbar. It’s unavailable until the data store has at least one Recode or Compute. For how Computes appear here, see Compute variables.
Actions tab
Section titled “Actions tab”Recodes are grouped by their source variable. Each shows its Output and its Status:
| Status | What it means |
|---|---|
| Pending | Queued, waiting to run |
| Running | Running now |
| Succeeded | Finished |
| Succeeded — source changed | Finished, but the source has changed since. The output is tagged STALE. |
| Succeeded — metadata warning | The values were written, but the output variable’s details weren’t fully updated |
| Failed | Didn’t finish. See Common Issues and Solutions. |
Use the Status filter to show only some of them. On a Recode that isn’t queued or running:
- Run again runs it straight away with the same rules. There’s no confirmation.
- Reopen opens it so you can change the rules first. See Reopen or run a Recode again.
Audit tab
Section titled “Audit tab”The Audit tab lists every run in the data store, newest first, with its Action, Input, Output, Status and Timestamp. A first run and a later run both show “Recode” as the Action.
Frequently Asked Questions
Section titled “Frequently Asked Questions”Does a Recode update when new data comes in?
No. A Recode runs once, when you click DONE or RUN AGAIN. If the source changes afterward, the output is tagged STALE. Reopen it and click RUN AGAIN to bring it up to date. For a recode that runs every time, use a wrangle’s Recode step.
Why can’t I see my variable in Available Variables?
It’s a type Recode can’t read (Date, Date Time, Time, Guid or Multi-Response), or its personal information is set to Mask, Mask + retention or Wipe. See Which variables you can recode.
Can I recode a published data store?
Yes. Creating and editing Recodes stays available after you publish.
Can I recode a survey’s variables?
Yes. You can use any eligible survey variable as the source. You can’t overwrite a survey’s variables, though, so the result goes into a new variable or one you’ve added in Data Wrangler.
Can I use two variables in one rule?
No. A Recode has one source, and each rule has one condition on it. You can pull other variables’ values into a Text result with @, but they can’t decide which rule matches.
What happens to records that don’t match any rule?
They fall to Else, which leaves them blank unless you choose Use a code, Use a value or Use text. Records with a blank source also fall to Else, unless a rule catches them with Is Missing or Include system-missing in this bucket.
Why are the preview numbers different from my whole data store?
The preview uses a sample of up to 1,000 records. When the Recode runs, it uses every record.
Does a Categorical Recode create a codeframe?
Yes. Your codes and labels become the new variable’s codeframe, so other apps show “Promoter” rather than 3. You can change it afterward in Codeframes.
Can I change a Recode’s source or type after it’s run?
No. When you reopen a Recode, the source, Variable Type and destination are locked. Start a new Recode instead.
What’s the difference between this and the wrangle Recode step?
This Recode works inside one data store, runs once, and gives you a preview as you build. A wrangle’s Recode step runs every time the wrangle runs and can write to another data store, but it has no preview. See Recode data.
Why don’t I see Add Variable or Manage Actions?
You can only view this data store. Ask the owner for Can Edit access.
Common Issues and Solutions
Section titled “Common Issues and Solutions””This name already exists. Choose a numbered alternative:”
Section titled “”This name already exists. Choose a numbered alternative:””Another variable already has the name in New Variable Name.
- Pick a suggestion - Click one of the numbered names shown under the message.
- Or type your own - Choose a name no other variable uses.
”Complete the required fields to finish:”
Section titled “”Complete the required fields to finish:””DONE is disabled because part of a rule or the output isn’t filled in. The list says what’s missing, for example “Between needs a lower and an upper value.” or “A label is required.”
- Read the list - Each item points to the field to fix.
- Fill it in - Check each rule’s IF and THEN CODE fields, and the Else row.
”Recode failed”
Section titled “”Recode failed””The Recode didn’t finish. The message says why, where it can. If you were overwriting a variable, its old values are kept.
- Read the message - It may tell you what to fix, such as a rule or a variable used in a Text template.
- Run it again - Open Manage Actions and click Run again, or reopen the Recode and click RUN AGAIN.
- Contact support - If it keeps failing, contact support with the data store’s name and GUID (copy it from Settings).
My output is tagged STALE
Section titled “My output is tagged STALE”“The source changed after this action ran. Reopen it to run again.” The output may be out of date. In Manage Actions, the Recode shows Succeeded — source changed.
- Reopen the Recode - Click Reopen Recode / Run again on the output variable’s row.
- Click RUN AGAIN - The output is recalculated from the current data.