SPSS Tutorials

BASICS REGRESSION T-TEST ANOVA CORRELATION

Insert Values from Output Tables into Text

Question

"I'd like automatically generate text reports in which some values from SPSS output tables are automatically inserted. Is this possible and if so, how?"

SPSS Python Syntax Example

*1. Save and modify some basic SPSS settings.

preserve.
set mpr off pri off tnu lab.
output close *.

*2. Retrieve some output values and insert them into text.

begin program.
import spssaux
cmd = spssaux.CreateXMLOutput('CROSSTABS v1 BY gender/cel col.')
print'''
We found that %s of the female respondents were 'Not at all satisfied' while %s of the male respondents were.
'''%(spssaux.GetValuesFromXMLWorkspace(cmd,'Crosstabulation',cellAttrib = 'text',colCategory='Female', rowCategory='Not at all')[0],
spssaux.GetValuesFromXMLWorkspace(cmd,'Crosstabulation',cellAttrib = 'text',colCategory='Male', rowCategory='Not at all')[0])
end program.

*3. Export output to .rtf document.

OUTPUT EXPORT
/CONTENTS EXPORT=ALL LAYERS=PRINTSETTING MODELVIEWS=PRINTSETTING
/DOC DOCUMENTFILE='D:\temp\report.doc'
     NOTESCAPTIONS=YES WIDETABLES=WRAP
     PAGESIZE=INCHES(8.5, 11.0) TOPMARGIN=INCHES(1.0) BOTTOMMARGIN=INCHES(1.0)
     LEFTMARGIN=INCHES(1.0) RIGHTMARGIN=INCHES(1.0).

*4. Restore SPSS settings as they were before they were modified.

restore.

Description

Previous tutorial: Regression over Many Dependent Variables

Next tutorial: Restrict Command to Variables having Minimum Valid N

Let me know what you think!

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

This tutorial has 2 comments