Introduction
Using SPSS keywords, especially TO and ALL greatly speeds up a myriad of typical tasks. This tutorial walks you through SPSS main keywords and points out how they can save time and effort. We'll use supermarket.sav for demonstrational purposes.

SPSS Main Keywords
Expression | Meaning | Returns |
---|---|---|
ALL | All variables (not previously addressed in statement) | Variable name(s) |
TO | All variables between and including | Variable name(s) |
BY | Split outcome of one variable by values of another | Nothing |
WITH | Compare one variable with another | Nothing |
SPSS ALL Keyword
SPSS ALL keyword returns all variable names that haven't been previously addressed in the same command in the order in which they occur in the data. For our data, simply using “ALL” thus returns v1, v2 [...] income. For example, we can run FREQUENCIES for all variables by
frequencies all.
generates frequency tables off all variables in the data in the order in which they occur.
A little known fact is that you can combine ALL with one or more variable names (possibly using TO). In this case, ALL refers to all variable names that didn't occur previously in some (sub)command. For example
frequencies income gender all.
generates frequency tables for income, gender and all other variables in the order in which they occur in the data.
SPSS TO Keyword - Existing Variables
SPSS TO keyword returns all variable names between and including the variable names that are specified in the order in which they occur in the data. For example frequencies v6 to v9. generates frequency tables for v6, v7, v8 and v9. The reason for this is that variables v7 and v8 are located between v6 and v9 in our data. The screenshot below illustrates this.

Now, a pitfall here is thinking that it's the variable names that determine what's returned by TO. We'll demonstrate this by reordering our variables. One way to do so is running sort variables by label. After reordering our variables, “FREQUENCIES V6 TO V9.” will address different variables. The screenshot below demonstrates why this is the case.

For the remainder of this tutorial, we'll reorder our variables by name by running sort variables by name.
SPSS TO Keyword - New Variables
Some commands can create multiple new variables at once. Some examples are RECODE, DO IF and the STRING command. In such cases, the TO keyword provides a handy shortcut for specifying multiple new variable names; for the first variable, specify a root name and a positive integer suffix as in “S1”. For the last variable, specify the same root and a higher suffix, such as “S5”. Like so, “S1 TO S5” tells SPSS to create S1, S2, S3, S4 and S5. Two examples are given below.
string s1 to s5(a1).
*2. The first suffix may be greater than 1 as long as it's a smaller integer than the last suffix.
string s117 to s154(a1).
SPSS BY Keyword
SPSS BY keyword is used for splitting outcomes of one variable by the values of another. The best known example is probably the CROSSTABS command as in crosstabs v1 by v2.

The resulting table can basically be described as “the frequency distributions of v1 for each value of v2 separately” or vice versa.
SPSS WITH Keyword
SPSS WITH keyword compares two variables. An example of such a comparison is SPSS Paired Samples T Test. A different example is correlations v2 to v4 with v1.

THIS TUTORIAL HAS 2 COMMENTS:
By Yacoub Seyni on June 16th, 2016
Thanks very much for your helpful tutorial! I am learning a lot :)
I just noticed a typo under "SPSS WITH Keyword", which occurs in the first sentence: "SPSS BY keyword compares two variables" should be "SPSS WITH keyword compares two variables".
Thanks again.
By Ruben Geert van den Berg on June 17th, 2016
Hi Yacoub! Thanks so much for pointing that out! I'll fix it in a minute, ok?