Display and Ordering of Variables

Variables can have different content, such as numbers only, or characters of the alphabet, or mixtures of both. Newer versions of SPSS allow for some special formats, such as "dates", etc. I cannot go into details here.

What is often neglected, however, is that the display of variables can be changed. This can mean several things: Number of decimals, the width of display, and the alignment of data values in the respective columns. Note that I treat only numerical variables here.

A remotely related issue is the order in which variables appear in a data set. This will be dealt with in the final section.


Number of decimals

FORMAT income (f6.0) var17 (f2.0).

The letter "f" indicates that the variable in question is a numerical variable. The number on the left hand of the decimal point refers to the overall number of numbers to be displayed, and the number on the right hand to the number of decimal values. In the example above, no decimal values will be displayed at all, but of course any meaningful format may be defined here; for instance, in some cases it may be necessary to have more that two decimal values. The number on the left hand should be larger than the number of decimals, but otherwise it doesn't really matter – a format of (f6.1) will yield the same result as a format of (f2.1).

Variable formats as defined here do not have any effect on the width of the columns in the data window. These will be changed with the next command.


Display width

VARIABLE WIDTH income (6) var17 (5).

It is meaningful to attach a width of 5 to var17 because otherwise the variable name will not fit into the column. Generally, defining a variable width may help you to fit more (or fewer, if desired) data values into the data window.


Alignment

VARIABLE ALIGNMENT income (CENTER) / var17 (LEFT).

The default setting is RIGHT, which is the way numerical values should be displayed. If, however, for some strange reason I cannot think of but which may exist somewhere in the world a different alignment should be desired, this can be effected the way shown here. Several variable names can be used with a single keyword.


Order of Variables

The order in which variables appear in a data set is utterly irrelevant for analysis. However, for data inspection purposes it may be desirable to have variables appear in a certain order other than that currently given.

SPSS provides no simple way to achieve this via explicit commands (i.e., via syntax); in particular, it's not easy to place just one or two variables somewhere else. For this purpose, you have to use the usual drag & drop or copy & past procedures within the data window.

However, if you want to completely rearrange your data set, it might be easier to do so via a syntax file. The trick to employ comes with other procedures: When saving a data file, you can tell SPSS to "keep" variables, and it will save the variables in the order they are listed in your SAVE command. If you do not want to save the data set with the re-arranged variables, you may also use MATCH FILES, which offers the same feature of keeping variables and doing so in the specified order. In the latter case, you just have to "match" the data set to itself.

So here's two simple examples, one for each of the two possibilities I just outlined. (Normally you would deal with so few variables via drag & drop, it's only for demonstration purposes.) Assume that you have a data set with variables var1, var2 and var3 and you wish to reverse the order in which the variables appear. Now, you just write

SAVE OUTFILE = "name_of_outfile"/KEEP var3 var2 var1.

or

MATCH FILE/FILE = */KEEP var3 var2 var1.

Of course it may be tedious to list all the variables when there are many of them. Luckily, there is a simple way if all you want to do is to move some variables to the first columns of the data file and leave the rest as it is. In this case, you may list the variables that are supposed to be moved to the first columns and adress the rest with ALL, as in

SAVE OUTFILE = "name_of_outfile"/KEEP id var30 var17 var11 ALL.

Here, id, var30, var17 and var11 will be moved to the first four columns; all other variables will appear in the same order as before.

© W. Ludwig-Mayerhofer, IGSW | Last update: 04 Oct 2016