Survey Programming Logic: A Practical Guide to Skips, Display Rules, Piping and Randomisation
Survey programming is where a questionnaire stops being a document and becomes a working instrument. The logic you build in, including skip rules, display conditions, piping and randomisation, decides whether each respondent sees a sensible, relevant interview or a confusing one that produces data you cannot trust. This guide walks through each type of logic, how they interact, and how to keep a script maintainable when the questionnaire changes for the fifth time.
What survey programming actually involves
A questionnaire written in a word processor is a set of instructions for humans. A programmer, sometimes called a scripter, translates those instructions into rules a survey platform can execute. That translation is rarely one-to-one. Questionnaire authors write notes such as "ask if aware" or "show brands used in the last month" and expect the programmer to resolve what "aware" means when three awareness questions exist.
Good survey scripting therefore has three parts:
- Interpretation: turning loose instructions into precise conditions, and raising queries when the instruction is ambiguous.
- Construction: building questions, answer lists, variables and logic in the platform.
- Documentation: recording what was built, so the next person (or you, in three weeks) can change it safely.
The third part is the one most often skipped, and it is the reason late changes cause so many errors.
The four logic families
Most of what a programmer builds falls into four families. They overlap, and the bugs usually live in the overlaps.
Skip logic (branching)
Skip logic moves a respondent from one point in the questionnaire to another based on an answer. The classic example is a screener: if a respondent says they have not bought the category in the past six months, skip to the end and close as a screen-out.
Skip logic is powerful but blunt. Every skip creates a path, and every path needs testing. When a questionnaire has many skips, it becomes hard to reason about which questions a given respondent will see. A useful habit is to keep skips for genuine routing decisions (screen-outs, module selection, terminating paths) and use display logic for the finer, question-level conditions.
Display logic (conditional questions and options)
Display logic decides whether a question, or an individual answer option, is shown at all. "Show Q12 only if Q5 = 1" is display logic. So is "show only the brands the respondent selected at Q3" at the option level.
Display logic tends to be easier to maintain than long chains of skips because each condition sits with the question it controls. The trade-off is that a respondent's path is now spread across many small conditions, so the programmer needs a clear way to see them all together, usually in a logic summary or flowchart.
Piping
Piping inserts an earlier answer, or a derived value, into later question text or answer lists. "You said you last bought [brand]. How satisfied were you with it?" is text piping. Carrying forward only the brands selected earlier is list piping.
Piping problems are among the most visible errors a respondent can see. Typical issues include:
- An empty pipe because the source question was skipped.
- Grammar that breaks when the piped value is plural, very long or includes "Other (please specify)" text.
- Piped open-ended text that has not been checked for length or offensive content before display.
Randomisation and rotation
Randomisation changes the order of answer options, questions, or whole blocks so that order effects are spread across respondents rather than biasing one option. Pew Research Center's methods guidance on writing survey questions explains that earlier questions can shape answers to later ones, and that rotating or randomising list items is a common way to deal with this, while ordinal scales are generally kept in their natural order.
In practice, the programmer must know which elements should be randomised, which must stay fixed ("None of these" and "Don't know" usually anchor at the bottom), and whether randomisation should be recorded in the data so analysts can check for order effects later.
How the logic types compare
| Logic type | What it controls | Typical use | Common failure |
|---|---|---|---|
| Skip logic | Respondent's path through sections | Screeners, module routing, terminations | Orphaned questions no path reaches |
| Display logic | Whether a question or option appears | Follow-ups, brand lists, conditional grids | Conditions referencing the wrong variable |
| Piping | Text or lists carried forward | Personalised wording, filtered lists | Empty pipes after a skipped source |
| Randomisation | Order of options, items or blocks | Brand lists, attribute batteries, concept tests | Anchored options randomised by mistake |
Building logic that survives change
Questionnaires change. Clients add a question after the soft launch, a quota is redefined, a country is added. The difference between a script that absorbs change and one that breaks is mostly structural.
- Name variables deliberatelyUse consistent, meaningful names so conditions read clearly and match the datamap.
- Build derived variables onceCreate a single hidden variable for concepts like "category buyer" and reference it everywhere.
- Keep conditions near their questionsPrefer display logic over long skip chains for question-level rules.
- Comment the non-obviousNote why a rule exists, not just what it does, especially for client-specific exceptions.
- Version every changeRecord what changed, when and why, and retest the affected paths.
Use derived (hidden) variables
If "aware of Brand A" depends on answers at three questions, calculate it once in a hidden variable and reference that variable in every later condition. When the definition changes, you change one place instead of hunting through twenty conditions.
Separate screening from the main questionnaire
Screener logic decides who qualifies and which quota cells they count towards. Keeping it in its own block, with clearly named qualification variables, makes it much easier to reconcile what the script did with what the quota plan expected. That alignment matters later when fieldwork is monitored against targets, which we cover in our survey quota management guide.
Plan for termination and over-quota paths
Every survey has at least three endings: complete, screen-out and over-quota. Some also have quality terminations for speeders or failed attention checks. Each ending should set a clear status variable and send the respondent to the right exit, because these statuses feed directly into supplier reporting and reconciliation.
Grids, loops and other structures that need care
Some question structures multiply the logic you need to manage.
- Grids and matrices: row-level display logic (show only brands used) combined with column randomisation can produce layouts that look fine on desktop but break on mobile. Check both.
- Loops: asking the same set of questions for each selected item (each brand, each store visited) requires the loop to pipe the current item correctly and to store answers in clearly separated variables.
- Max-diff and conjoint designs: these usually rely on pre-generated design files. The programmer must confirm the design loads correctly and that each respondent's version is recorded.
- Multi-language scripts: logic should be language-independent. Conditions that check answer text rather than codes will break the moment a translation is added.
Data quality starts in the script
Logic is not only about routing; it is also your first line of defence for data quality. Common in-script checks include:
- Validation on numeric answers (ranges, sums that must equal 100).
- Attention or consistency checks placed where they do not disrupt the experience.
- Minimum length or pattern checks on open-ended answers, applied carefully so genuine short answers are not rejected.
- Timing variables that make speeders easy to identify afterwards.
These checks work best alongside post-field review rather than replacing it. Our article on online survey data quality checks covers the analysis side in more detail. The AAPOR best practices for survey research also recommend pretesting the questionnaire and monitoring data quality during fielding, which is a good reminder that programming and quality control are linked activities.
| Area | Ad hoc scripting | Structured scripting |
|---|---|---|
| Variable names | Whatever the platform defaults to | Agreed convention that matches the datamap |
| Complex conditions | Repeated inline at each question | Calculated once in derived variables |
| Late changes | Edited in place, partially retested | Versioned, with affected paths retested |
| Handover | Knowledge lives with one programmer | Logic summary and comments travel with the script |
Working with the questionnaire author
Many logic errors are really communication errors. A short query log between the programmer and the questionnaire author prevents most of them. Useful habits include:
- Reading the whole questionnaire before building anything, and listing every ambiguity in one pass.
- Confirming base definitions ("ask all aware" means aware at which question?) in writing.
- Agreeing which elements randomise and which anchor.
- Sharing a test link with a logic summary, so the author can check paths rather than just wording.
Once the script is built, it moves into testing. We have written a separate questionnaire-to-live-survey checklist covering QA, soft launch and go-live.
Where Sampledge fits
SampCode is the survey scripting and programming product in the Sampledge ecosystem, built by Frequent Research for research teams that program surveys every week. Because it sits alongside SampTrek research project management, the survey a programmer builds can belong to the same project record as its quotas, suppliers and fieldwork, rather than living in a separate tool. You can see how the products connect on our how it works page.
If you want to see how SampCode would handle your next questionnaire, book a demo with our team or create a workspace and explore it yourself.
Frequently asked questions
Survey programming is the work of turning a written questionnaire into a working online survey, including questions, answer codes, routing, validation and data variables.
Skip logic moves a respondent to a different point in the survey, while display logic decides whether an individual question or answer option is shown at all.
Piping inserts an earlier answer or derived value into later question text or answer lists, such as showing only the brands a respondent selected earlier.
No. Unordered lists such as brands are often randomised to spread order effects, but ordinal scales and anchored options like "None of these" usually stay fixed.
Use consistent variable names, calculate complex conditions once in derived variables, comment non-obvious rules and version every change with retesting of affected paths.
SampCode is the survey scripting and programming product in the Sampledge ecosystem, built by Frequent Research and designed to sit alongside SampTrek project records.
See it with your own projects in mind.
Book a short demo, or create a free account and look around.