The Joy of Pasting SPSS Syntax

by Karen Grace-Martin

Every so often I point out to a client who exclusively uses menus in SPSS that they can (and should) hit the Paste button instead of OK. Many times, the client never realized it was there.

I am here today to tell you that it is there, and it is wonderful.  For a few reasons.

When you use the menus in SPSS, you’re really taking a shortcut.  You’re telling SPSS which syntax commands, along with which options, you want to run.

Clicking OK at the end of a dialog box will run the  menu options you just picked. You may never see the underlying commands that SPSS just ran.

If instead you hit Paste, those command won’t automatically be run, but will instead the code to run those commands will be copied into the Syntax window.

You can then, through the syntax window, run all or part of the syntax commands.

Having all your commands in the Syntax Window Saves so Much Time

I’ve already written about reasons to use syntax, so I won’t repeat myself.  I’ll just mention that most of those are about saving time.

Just last week I met with a client who is nearly done with her dissertation.

She mentioned that she had started using syntax just recently, toward the end of her project.  She wished she’d started earlier because it was so much easier and faster than running through the menus.

But she didn’t know about the Paste button.  She’d been running each command, then copying the syntax out of her output into the syntax window.

You don’t have to remember every little command option

I was recently at a one-day regional statistics conference and attended an introductory talk about using R.  It was less than an hour, so was really just a demonstration.

As you probably know, I am not a regular R user, but have some experience with it.  So I was able to follow along pretty easily.

What struck me most was not that R was difficult (as seems to be the general perception), but that it could be very frustrating if you don’t use it on a regular basis.

It’s pretty logical, and the commands make sense. With some good basic training, it looks quite doable.  What struck me though, is what an advantage the Paste button is in SPSS.

With the Paste button you don’t have to remember the exact syntax to get a command to run exactly the way you want it.

Need to run 20 different crosstabs but don’t remember the exact option to get row percentages?  Just run one through the menus, and hit paste.  Copy and paste it 19 times, then change the relevant variable names.  Easy-peasy.

(Now, to be fair to R, there very well may be a way to do the same thing.  The talk demonstrated quite clearly that using a plugin like R-Studio would make life much easier.  I know there are a number of GUIs for R.  If you know of one that does allows you to paste the code, please share in the comments.

And secondly, savvy programmers always save their code and edit it for other programs).

One way I like to use the Paste command to save time

If you’ve ever analyzed a large data set using the menus, you already know how tedious it can be to find the variables you need in the long list of variables.  This is especially true when the variable names are all very similar.

It drives me nuts, personally.

So in my impatience, I’ve realized how to use Paste to my advantage.  Let’s say I want to run a crosstab on two variables whose names I know, but  I can’t find them in the list of variables.

But I also don’t remember the exact syntax commands.

I run a crosstab through the menus and pick any two variables.  Paste the syntax.

Now I edit my syntax in the syntax window using the variable names I can remember without having to find them in a long list.  Then I run it.

Bookmark and Share

If you’d like to learn more about how to use SPSS, both in menus and syntax, take a look at our online workshop Introduction to Data Analysis with SPSS.

{ 5 comments… read them below or add one }

Dhritiman Chakrabarti

I would like to add to the topic of syntax editing with the use of “Concatenate” function of Microsoft Excel. If you need to run the same syntax for a number of variables, it is quite tedious to copy and paste each variable separately. Since most of the syntax other than the variable name is invariant, I just create a column of the same in an excel spreadsheet and in the adjoining column, I paste the variable name which we require and join the text of two columns using concatenate function of excel.
This gives us a column of syntax of multiple variables to be directly pasted into SPSS and get the results.
I use the same method for R too, if I am running multiple models. In R, looping might allow you to do the same, but I am not very familiar with it as of now.


Michael Moore

Hi, Karen.

Thanks for this great article, as well as “Non-parametric ANOVA in SPSS”. Actually, my question concerns both topics.

Do you know of any syntax commands that will allow me to adjust the p-value (Bonferroni adjustment) for Mann-Whitney post-hoc tests, after a Kruskal-Wallis test has indicated a significant difference in ranks? My version of SPSS doesn’t give me the option to adjust p-values on the menus of non-parametric tests.

Any help will be much appreciated. Thanks!



Hi Michael,

You don’t adjust the p-value with Bonferroni, you adjust alpha.

So nothing to do in SPSS. Just take the p-value you get, and state the new value of alpha/k (where k is the number of tests) that you’re comparing that p to.


Michael Moore

Thanks, Karen!




R-Studio is an IDE and not a plug-in. R-Commander (you could call it a plug-in) allows for clicking menues but actually generates R syntax to be copy and pasted
Same goes for JGR and I guess also for RKWard (Linux only)


Leave a Comment

Please note that, due to the large number of comments submitted, any comments on problems related to a personal study/project will not be answered. We suggest joining Statistically Speaking, where you have access to a private forum and more resources 24/7.

Previous post:

Next post: