SPSS – Shortening Long Variable Names

A common problem with SPSS data files are unlabeled variables with huge names. These cause several problems:

  1. editing and analyzing your data takes too much time and effort;
  2. your syntax becomes unreadable and unmanageable;
  3. your output looks terrible.

The way to go in this case is setting such variable names as labels. Next, set nice and short variable names. How? I'll show a quick way to do so trials.sav, part of which is shown below.

SPSS Fix Long Variable Names Variable View

1. Copy-Paste Variable Names into Googlesheet

A nice and easy way to fix the problem starts with opening a Googlesheet. Next:

The result is in this spreadsheet.

SPSS Fix Long Variable Names Google Sheet

2. Copy-Paste Googlesheet into SPSS Syntax

Now copy-paste all contents of our Googlesheet into an empty SPSS syntax window. Replace double quotes followed by a tab by just double quotes as shown below.

SPSS Fix Long Variable Names In Syntax SPSS Fix Long Variable Names Google Sheet

Finally, add VARIABLE LABELS in front of all syntax and a period at the end. This results in the syntax below. Running it sets nice variable labels for all variables with long names.

3. Move Variable Names into Labels Syntax

variable labels Trial_1_Answer "Trial 1 Answer "
Trial_1_Reaction_Time_Milliseconds "Trial 1 Reaction Time Milliseconds "
Trial_2_Answer "Trial 2 Answer "
Trial_2_Reaction_Time_Milliseconds "Trial 2 Reaction Time Milliseconds " /*... AND SO ON UNTIL ...*/
Trial_20_Answer "Trial 20 Answer "
Trial_20_Reaction_Time_Milliseconds "Trial 20 Reaction Time Milliseconds ".

4. Shorten Variable Names

Now that we set our excessively long variable names as variable labels, we can safely shorten our variable names with a single line like rename variables (Trial_1_Answer to Trial_20_Reaction_Time_Milliseconds = v1 to v40). The final result is shown below.

Final Result

SPSS Long Variable Names Into Labels Final Result

The entire operation took some 3 minutes. However, it'll save a lot of time and headaches when we start editing and analyzing these data. On top of that, my newly set variable labels look great in output tables!

Final Notes

For keeping things nicely organized, you could run the VARIABLE LABELS syntax with INSERT. This command runs an entire syntax file without having to open it.
Second, Googlesheets allow you to create many lines of errorless syntax fast. In this example, we set some variable labels but you could run a lot of scatterplots in a similar way.
A better alternative for such tasks, however, is Python for SPSS. It allows you to do much more -and way faster. If you can find the time, try to learn some.

Thanks for reading!

Tell us what you think!

*Required field. Your comment will show up after approval from a moderator.