Stats Work

Compressing Long Lists of Variables for Tidier SPSS Syntax

You just pasted a long list of variables into your SPSS syntax that you want to delete from or rename in your dataset.

Maybe you normally just leave it as is or maybe you manually compress the list with a committed effort of backspaces and spaces. Both options I find quite frustrating: you either deal with the laggy scrolling of SPSS as you move up and down your syntax for the former (which is even more frustrating if you have thousands of variables and you’re still working on the syntax) or you let it consume your time as you meticulously work through the list for the latter.

Well, I’m here to tell you about one way I’ve found to quickly compress long lists of variables.

Step 1: Copy and paste your variables into Microsoft Word.

Step 2: Go to Edit -> Find -> Replace…

Step 3: In the Find menu, select “Paragraph Mark” and within the Replace menu, manually press the spacebar once to effectively replace paragraph marks with a single blank space (you could also use the dropdown menu to select “Nonbreaking Hyphen” or “Nonbreaking Space”). Press Replace All.

Formatting marks (the blue markings) are shown for clarification
Formatting marks (the blue markings) are shown for clarification

Step 4: With the list now compressed into a single paragraph, you can either copy and paste this into your syntax and add in the paragraph breaks where you desire (as this will just give you one long row of variables) or you can add in the paragraph breaks within Word first and then copy it into your syntax (example below)

Paragraph breaks manually added in Word, again format markings shown for clarification
After adding paragraph breaks in Word, this is what it will look like after copying and pasting it into your syntax.

That’s it! Depending on how many variables you have, the manual paragraph breaks afterwards can still be a bit time consuming, but much less time consuming than removing the paragraph breaks one variable at a time within the syntax.

If you are aware of an even faster approach, please let me know. If not, I hope this helps! Happy syntaxing.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s