SPSS tutorials website header logo SPSS TUTORIALS BASICS DATA ANALYSIS REGRESSION ANOVA T-TESTS

SPSS Label Cleaning Tool

We sometimes receive data files with annoying prefixes or suffixes in variable and/or value labels. This tutorial presents a simple tool for removing these and some other “cleaning” operations.

Example Data File

All examples in this tutorial use dirty-labels.sav. As shown below, its labels are far from ideal.

SPSS Label Cleaning Tool Variable View

Some variable labels have suffixes that are irrelevant to the final data.
All value labels are prefixed by the values that represent them.
Variable and value labels have underscores instead of spaces.

Our tool deals with precisely such issues. Let's try it.

Prerequisites and Installation

First off, this tool requires SPSS version 24 or higher. Next, the SPSS Python 3 essentials must be installed, which is normally the case with recent SPSS versions.

Next, click SPSS_TUTORIALS_CLEAN_LABELS.spe for downloading our tool. You can install it by dragging & dropping it into a data editor window. Alternatively, navigate to Extensions SPSS Menu Arrow Install local extension bundle as shown below.

SPSS Extensions Install Local Extension Bundle

In the dialog that opens, navigate to the downloaded .spe file and select it. SPSS now throws a message that “The extension was successfully installed under Transform - SPSS tutorials - Clean Labels”.

Example I - Text Replacement over Variable and Value Labels

Let's first replace all underscores by spaces in both variable and value labels. We'll open Transform SPSS Menu Arrow SPSS tutorials - Clean Labels and fill out the dialog as shown below.

SPSS Label Cleaning Tool Dialog 1

Completing these steps results in the syntax below. Let's run it.

*Replace underscores by spaces in all value and variable labels.

SPSS TUTORIALS CLEAN_LABELS VARIABLES=v1 v2 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16 v17 v18 v19
    v20 v21 v22 FIND='_' REPLACEBY=' '
/OPTIONS OPERATION=FIREPCONT PROCESS=BOTH ACTION=BOTH.

Results

First note that all underscores were replaced by spaces in all variable and value labels. This was done by creating and running

commands. We chose to have these commands printed to our output window as shown below.

SPSS Label Cleaning Tool Output 1

SPSS already ran this syntax but you can also copy-paste it into a syntax window. Like so, the adjustments can be replicated on any SPSS version with or without our tool installed. If there's a lot of syntax, consider moving it into a separate file and running it with INSERT.

Example II - Remove Suffix from Variable Labels

Some variable labels end with “ (proceed to question...” We'll remove these suffixes because they don't convey any interesting information and merely clutter up our output tables and charts.

Again, we start off at Transform SPSS Menu Arrow SPSS tutorials - Clean Labels and fill out the dialog as shown below.

SPSS Label Cleaning Tool Dialog 2

Quick tip: you can shorten the resulting syntax by using

We did just that in the syntax below.

*Remove " (proceed" and characters succeeding it from all variable labels.

SPSS TUTORIALS CLEAN_LABELS VARIABLES=all FIND=' (proceed' REPLACEBY=' '
/OPTIONS OPERATION=FIOCSUC PROCESS=VARLABS ACTION=RUN.

Note that running this syntax removes “ (proceed to” and all characters that follow this expression from all variable labels.

Example III - Remove Prefix from Value Labels

Another issue we sometimes enounter are value labels being prefixed with the values representing them as shown below.

SPSS Label Cleaning Tool Variable View

Removing “= ” (mind the space) and all characters preceding it from all value labels fixes the problem. The syntax below -created from Transform SPSS Menu Arrow SPSS tutorials - Clean Labels- does just that.

*Remove "= " and characters preceding it from all value labels.

SPSS TUTORIALS CLEAN_LABELS VARIABLES=all FIND='= ' REPLACEBY=' '
/OPTIONS OPERATION=FIOCPRE PROCESS=VALLABS ACTION=RUN.

Result

After our third and final example, all value and variable labels are nice, short can clean.

SPSS Label Cleaning Tool Results 1

So that'll wrap up the examples of our label cleaning tool.

Final Notes

I hope you'll find our tool as helpful as we do. This first version performs 4 cleaning operations that we recently needed for our daily work. We'll probably build in some more options when we (or you?) need them.

So if you've any suggestions or other remarks, please throw us a comment below. Other than that,

thanks for reading!

Tell us what you think!

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