SPSS tutorials


SPSS Table Templates


SPSS table templates are files that tell SPSS how to style one, many or all tables that appear in the output viewer window. Some examples of such styling are the colors and sizes of fonts and borders. The figure below shows a DESCRIPTIVES table with and without a table template applied to it.

SPSS table template Example 1

Just like SPSS data files are sometimes called .sav files, SPSS table templates are also known as .stt files after their file extensions and we'll use these two terms interchangeably. Now, for really geting a grip on SPSS table templates, let's first recreate the table from the previous figure. We'll do so by opening freelancers.sav and running the syntax below on it.

SPSS Table Creation Syntax

*1. Specify 99999997 as user missing.

missing values income_2011(99999997).

*2. Suppress excessive decimal places by setting formats.

formats income_2010 income_2011(dollar9).

*3. Show only variable labels (not names) in table.

set tvars labels.

*4. Standard descriptives table.

descriptives income_2010 income_2011/statistics mean.

SPSS Table Templates - Why Use Them?

Perhaps you'd like to report the table we just created. If so, you'll probably want it to look better than it currently does. Now, you can manually style the table by first double clicking it and then right clicking it and selecting “Table Properties” as shown below. After doing so, you'll easily figure out how to apply some styling.

SPSS Table Styling Manually

Styling a table manually is not recommended; it's a lot of work and perhaps you'll want to fine tune and rerun your work at some point. Fortunately, you can easily save your current table styles as an SPSS table template (.stt) file and apply it to other tables. Alternatively, you can use one of the table templates that are included in SPSS by default.

Applying SPSS Table Templates Manually

We'll now manually apply a table template to the table we just created: just double click some table and then right click it and select “TableLooks” As shown below, we can now either apply an existing template to the selected table or save the current styles of the selected table as a new .stt file.

SPSS Table Template - Apply Manually

We'll select the last entry called “Warning”. Upon clicking Ok all styles are applied to the table at once.

Applying SPSS Table Templates by Syntax

Although applying table templates manually is less work than styling tables manually, we still find it very inefficient. Fortunately, there's a much better alternative: if we set a table template by syntax, it will be applied to all tables we create after doing so until we tell SPSS to stop using it.
The syntax below shows uses SET for setting a table template and SHOW for confirming it's been set. Before running it, let's first take a close look at the path in step 1.
Now, on our system, SPSS is installed in C:\Program Files\IBM\SPSS\Statistics\22. Here we find a folder called “Looks” that contains a number of .stt files. One of those is Warning.stt that we applied earlier. Its absolute path on our system is therefore C:\Program Files\IBM\SPSS\Statistics\22\Looks/warning.stt.

SPSS Set Table Template by Syntax

*1. Set SPSS Table Template.

set tlook 'C:\Program Files\IBM\SPSS\Statistics\22\Looks/warning.stt'.

*2. See which SPSS Table Template is in effect.

show tlook.

*3. Run descriptives table with SPSS Table Template applied to it.

descriptives income_2010 income_2011/statistics mean.

*4. Stop applying SPSS Table Template and use default tlook.

set tlook none.

SPSS Table Templates - What Are They?

Now that we've seen how to apply table templates, let's take a closer look at what they really are. Technically, SPSS table template files are simple text files that can be opened and edited with notepad++.
SPSS table templates contain style definitions in XML. Instead of styling a table manually and saving its styles like we saw earlier, some visitors (and the author) may find it faster to directly edit the XML contained by the template in Notepad++. Like so, you can get things done that you can't otherwise but this requires some practice.

SPSS Table Templates - Relative Paths

A previous tutorial made the suggestion of keeping all project files organized together in a project folder. We strongly recommend you copy any table templates you use for some project to this folder as well; in case you'd ever want to replicate (part of) your work, you can be confident you'll still have them available.
We very often use the CD command for setting our project folder as SPSS' default folder. This renders our syntax cleaner and more flexible in case we move the entire folder. Now, something awkward here is that CD works for all SPSS files (data, syntax, chart templates) except table templates. A workaround to this is defining the project folder as a very tiny macro. The syntax below demonstrates how to do so.

Set Project Folder as Macro Syntax

*1. Create macro containing default folder.

define !cd() 'd:/project/' !enddefine.

*2. Now use '!cd' instead of full path.

set tlook !cd + 'desc_standard_no_title.stt'.

*3. Run descriptives with SPSS Table Template applied.

descriptives income_2010 income_2011/statistics mean.

SPSS Table Templates - Showcase

Readers who have the SPSS Python Essentials installed and running can loop over all table templates that SPSS comes with. The syntax below does just that. Note that rdir (boldfaced in the syntax below) should be set to the previously mentioned folder holding the .stt files. The following screenshot shows how our table is generated once with each template applied to it.

Python Loop over Table Templates Syntax

*Create separate table for each SPSS Table Template file in Looks folder.

begin program.
rdir = r'C:\Program Files\IBM\SPSS\Statistics\22\Looks' #Set to SPSS Looks folder
import spss,os
for stt in [fil for fil in os.listdir(rdir) if fil.endswith('.stt')]:
title %s.
set tlook '%s'.
descriptives income_2010 income_2011/statistics mean.
end program.

SPSS Table Template Examples

SPSS Table Template Examples IBM

Previous tutorial: Set Decimals for Output

Next tutorial: Draw a Stratified Random Sample

Let me know what you think!

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

This tutorial has 4 comments