Automating Likert‑scale Recoding in SPSS with DO REPEAT
Learn how to use SPSS DO REPEAT loops to recode multiple Likert‑scale items in a single block, compute a scale score, and verify the results safely.
14 Aug 2025, 00:00 UTC

Why manual recoding becomes a bottleneck
When you have dozens of survey items that use the same response scale, recoding each one by hand in the SPSS Syntax Editor is tedious and error‑prone. A single typo can propagate through your analysis, and updating the recoding rule later means editing many lines of code. SPSS offers a compact way to apply the same transformation to a list of variables: the DO REPEAT loop.
How DO REPEAT works
The DO REPEAT construct lets you define a placeholder that iterates over a list of variables (or values). Inside the loop you write the transformation once; SPSS repeats it for each item in the list. The basic syntax is:
DO REPEAT placeholder = var1 var2 var3 ... varN.
/* transformation using &placeholder */
END REPEAT.
PRINT.
The placeholder can be used in any command that accepts a variable name, such as RECODE, COMPUTE, or IF. After the loop ends, SPSS automatically drops the placeholder, leaving only the new (or modified) variables in the active dataset.
Worked example: recoding five Likert items
Suppose you have five items measuring job satisfaction, named JS1 through JS5, each scored 1–5 where 1 = “Strongly disagree” and 5 = “Strongly agree”. You want to convert them to a 0–4 scale (subtract 1) and then compute a simple sum score.
Step 1: Recode the items
DO REPEAT item = JS1 JS2 JS3 JS4 JS5.
RECODE item (1=0) (2=1) (3=2) (4=3) (5=4) INTO item_R.
END REPEAT.
EXECUTE.
This block creates five new variables: JS1_R through JS5_R, each holding the 0–4 values. The original items remain unchanged, which is useful for audit trails.
Step 2: Compute the scale score
COMPUTE JS_SUM = JS1_R + JS2_R + JS3_R + JS4_R + JS5_R.
EXECUTE.
Now JS_SUM ranges from 0 to 20, representing the total satisfaction score.
Trade‑offs and limitations
- No forward reference: Variables created inside the
DO REPEATblock (e.g.,item_R) cannot be used later in the same loop. If you need to chain transformations, you must run a second loop or use a temporary variable. - Readability with many items: When the variable list grows to dozens or hundreds, the generated syntax can become hard to scan. In those cases, consider defining a macro or using an external Python/R script to generate the loop.
- Complex conditionals: For intricate logic that depends on multiple variables or nested
IFstatements, aLOOPwith explicit indexing may be clearer.
Verification checklist
- Work on a copy of your dataset (
FILE HANDLE copy /name='C:\temp\data_copy.sav'.GET FILE='original.sav'.SAVE OUTFILE='copy.sav'.) to avoid overwriting production data. - Paste the
DO REPEATblock into a new Syntax Editor window and run it (RUNbutton orCTRL+R). - Open Data View and confirm that
JS1_RthroughJS5_Rappear with the expected 0–4 values for a few randomly selected cases. - Check the
JS_SUMvariable; compare its value for those cases against a manual calculation (e.g.,(JS1-1)+(JS2-1)+…) to ensure correctness. - Review the Output Log for any warnings or errors; if present, correct the syntax before proceeding.
Actionable next steps
Start by applying the pattern to a small subset of your variables. Once you’re comfortable, expand the list to cover all items in a scale. Remember to keep a backup, verify the results, and document the syntax in your project’s syntax library for future reuse.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.