I wrote a Python script for SPSS that I need to use a couple of times in a syntax. Thus, I would like to avoid repeating BEGIN PROGRAM-END PROGRAM.
structure more than once. I decided to place it within a macro but sadly it doesn't work even though there are no bugs neither in a macro nor a script. Code:
define mac_export (!positional !tokens(1))
OUTPUT EXPORT
/CONTENTS EXPORT = visible LAYERS = printsetting
MODELVIEWS = printsetting
/XLSX DOCUMENTFILE = "tables1.xlsx"
OPERATION = createsheet
sheet = !quote(!unquote(!1))
LOCATION = lastcolumn NOTESCAPTIONS = no
!enddefine.
define clean ()
begin program.
import spss, SpssClient
SpssClient.StartClient()
OutputDoc = SpssClient.GetDesignatedOutputDoc()
OutputDoc.SelectAllText()
OutputDoc.Delete()
OutputDoc.SelectAllLogs()
OutputDoc.Delete()
OutputDoc.SelectAllNotes()
OutputDoc.Delete()
OutputDoc.SelectAllTitles()
OutputDoc.Delete()
OutputDoc.SelectAllWarnings()
OutputDoc.Delete()
end program.
!enddefine.
*** REPORT.
ctables
/table
(att1 + att2 + att3)
[s][mean f1.1]
/slabels position = column visible = no
/titles title = "Attitudes".
clean.
mac_export "Attitudes".
ctables
/mrsets countduplicates = no
/table gender > $STATEMENTS [colpct.responses.count f40.0] by age
/slabels position = column
/titles title = "Statements".
clean.
mac_export "Statements".
* AND OTHER TABLES...
When I run this code SPSS stops at the first call of clean
macro. What can I do to simplify my code and avoid repeating BEGIN PROGRAM
structure?