SPSS doesn't offer an easy way to set decimal places for output tables. This tutorial proposes a very simple tool for setting decimal places in basic output tables after they've been produced. It works best for simple tables such as DESCRIPTIVES, MEANS or CROSSTABS.
Setting Decimal Places for Output Tables
- First, make sure that the SPSS Python Essentials are installed and run properly.
- Download and double click the SPSS Output Decimals Tool to install it. Note that this is an SPSS custom dialog.
- Run one or more tables, for example with DESCRIPTIVES, MEANS or CROSSTABS. Select one or more of them in the output viewer window.
- Go to .
- Choose which columns you'd like to process for all selected tables and the desired number of decimal places.
- Click syntax. or and run the
- Different decimal places for different columns can be set by running the tool repeatedly over the same tables, specifying different columns and decimal places in each run.The syntax example shows how to do this fast.
Specifying Columns
The diagram below illustrates how to specify columns. Note that the first “columns” don't count; according to SPSS pivot table terminology, these are not columns but row labels.This distinction is important for SPSS table templates (.stt files) as well as the Python scripting used by the tool.
Note that row and column labels are never affected by the Output Decimals tool. Although the diagram shows value labels (“Very bad” and so on) here instead of values, this is not always the case. If values are shown, then decimal places for row and column labels can easily be set by FORMATS.
SPSS Decimal Places in Output - Alternatives
- Since Python was introduced in SPSS version 14, Python scripting is the way to go for setting decimal places for output tables. The level of control it offers is basically unlimited but most users may find Python scripts hard to write and they require a lot of syntax. The output decimals tool uses Python scripting under the hood.
- The classical approach to setting decimal places for output tables is an SPSS script. Note that SPSS scripts (.sbs files) are very different from SPSS syntax (.sps) files. SPSS scripts are considered deprecated since Python scripting was introduced as its successor in SPSS version 14.
- SPSS OUTPUT MODIFY can be used for modifying basically anything about SPSS output tables including decimal places and text styles. Due to its complexity, however, we find it rather hard to get things done with it. Personally, we strongly prefer simpler tools even if they offer less functionality.
SPSS Python Syntax Example
Instead of using the Custom Dialog we just discussed, you may click here for an SPSS Python syntax version of this tool, including some basic tests for our tool.
data list free/id.
begin data
0 0 0 0 0 0 0 0 0 0 0
end data.
do repeat v = v1 to v5.
compute v = rv.binom(5,.5).
end repeat.
************20. GENERATE SOME TABLES.
descriptives v1 v2.
means v1 by v2.
crosstabs v1 by v2/cells column.
************30. DEFINE FUNCTION.
begin program.
def setOutputDecimals(cols,decs):
import SpssClient
SpssClient.StartClient()
outputDoc = SpssClient.GetDesignatedOutputDoc()
outputItems = outputDoc.GetOutputItems()
for index in range(outputItems.Size()):
outputItem = outputItems.GetItemAt(index)
if outputItem.GetType() == SpssClient.OutputItemType.PIVOT and outputItem.IsSelected():
pTable = outputItem.GetSpecificType()
dataCells = pTable.DataCellArray()
for row in range(dataCells.GetNumRows()):
if cols.lower() != 'all':
try:
colList = [int(col) - 1 for col in cols.split(',')] #Because indexed at 0
except:
print "Invalid column specification. Please specify positive integers separated by commas or the 'ALL' keyword."
break
else:
colList = range(dataCells.GetNumColumns())
for col in colList:
try:
dataCells.SetHDecDigitsAt(row,col,decs)
except:
pass
SpssClient.StopClient()
end program.
************40. TEST: SELECT (ONLY) DESCRIPTIVES TABLE IN OUTPUT AND RUN.
begin program.
setOutputDecimals('2,3',0)
setOutputDecimals('4',1)
setOutputDecimals('5',2)
end program.
************50. TEST: SELECT (ONLY) MEANS TABLE IN OUTPUT AND RUN.
begin program.
setOutputDecimals('1',1)
setOutputDecimals('3',2)
end program.
************60. TEST: SELECT (ONLY) CROSSTAB IN OUTPUT AND RUN.
begin program.
setOutputDecimals('all',0)
end program.
THIS TUTORIAL HAS 17 COMMENTS:
By Ruben Geert van den Berg on November 14th, 2015
Wow, that really surprises me! Could you please provide me some detailed information and try a couple of possible workarounds? I really want to fix this problem but as yet I can't replicate it.
-Which operating system/browser do you use?
-Did you try another browser (if you have any installed)?
-And what's the exact filename of the .zip file?
-If you simply change the ".zip" extension to ".spd", then are you able to install it from within SPSS as I suggested previously?
-Is this the first time you're using one of our Custom Dialogs? If so, could you please try another one and see whether you get similar symptoms? An example is the Mean Center Variables?
-If you hover over the link, what URL do you see? I believe Safari doesn't show any but in Google Chrome, I see this.
Please let me know. If everything else fails, I'll try and send the file over email, OK? Thanks a lot!!
By Carol on November 14th, 2015
OMG, easy peasy! I tried Google Chrome and it all worked perfectly -- clicked on the link and then got the spd file!
Originally I was using Internet Explorer 11. Hovering above the link shows "download Output Decimals Tools (file size around 3kB)" exactly as you would expect. But when I click that link I have the option only to open/save set_decimals_output_table.zip -- no spd file in sight.
Thanks for being so patient with me.
By Ruben Geert van den Berg on November 15th, 2015
Thank you for pointing out this IE11 issue! This allows me to replicate the problem and -hopefully- solve it (although you never know when it comes to Internet Explorer...).
Happy to hear things worked out in the end!
P.s. we may rewrite this tool as an SPSS Extension Bundle in a couple of months. This would be much more useful than the current Custom Dialog version.
By Yaser Pourdavar on April 26th, 2016
Hi Ruben
I have SPSS 23 installed on my computer.
I installed "SPSS Output Decimals Tool" Successfully! BUT now I have a problem with "SPSS toolbars":
I can't see toolbars anymore.
How can I fix it?
Thanks
By Yaser Pourdavar on April 26th, 2016
Sorry,
I have SPSS 22 installed on my computer.