Scripting is Heavy Duty Stuff!
- Introduction to SPSS scripting (a.k.a. SAX Basic)
- Index of Sample Scripts
- Sample Scripts
- VB Programs (an alternative to SPSS Production
facility)
Scripts are relatively new to SPSS. If you have never used Visual Basic (VB) or Visual
Basic for Applications (VBA), you will find the learning curve to be pretty steep. SPSS
uses Sax Basic developed by Sax Software. By adding Sax's Type Library to your
favourite VB development environment (for instance, VB6, Excel or Access) you may develop
your SPSS scripts using those development environments.
Scripts allow the user to do things which would not be possible using syntax, for
instance formatting an IGRAPH or having error handlers. Whenever possible, I prefer to use
syntax instead of scripts. As my knowledge of syntax increased, I discovered ways to
do things which I previously thought only scripting could do, one such example is
exporting or creating a variable which contains the value labels of another
variable.
Scripts can be called from syntax and vice versa. However a major problem is that a
script called from anywhere in a syntax could be executed after the
syntax file has finished! The same problem exists when a script calls a
syntax, that syntax could only be executed once the script has finished. Note that Fabrizio Arosio has developed a
script (see Utilities below) which circumvents this
"asynchronous" problem. I tested it and it works, however, you must ensure that
there are no trailing spaces at the end of your syntax (otherwise there is an infinite
loop). See the asynchronous page to
find out more about this issue.
Note that Scripting is not available in SPSS for Mac.

** Important Download Instructions **
Note: At the suggestion of a visitor, I have changed the extension of
the *.sbs files to *.txt, this makes it easier to look at the files online. When you click on an *.sbs file below,
it opens up in your browser as a text file. If you like what you see,
go
back to the prior page, right click on the file name as select "Save target
as").
Copying the code and pasting it directly into an SPSS script window sometimes results in the loss
of the line breaks; all lines are saved consecutively in the same line, this is
not very useful :-(

The scripts files are broadly classified by purpose as
follows:
- Autoscripts
- Data Document
- Dialogs
- Distributions
- Draft Output
- Effect Size
- IGRAPH
- Import Export (see also the corresponding syntax section)
- Labels (see also the corresponding syntax section)
- Long Variable Names (version 12+)
- Output Format
- Output Document
- Printing
- Pivot Tables
- Syntax Doc
- Transform Data
- Utilities
- Working With Many Files (see also the corresponding syntax section)

Show me data and I will show you data errors!

Note: Files with a
at the end were added or modified less than 30 days ago.
|
|
- AutoExperiment.SBS
To help in the debugging of autoscripts
-
Bold Total in SUMMARIZE table or insert Page Break.SBS
This is an example of a syntax which passes an argument to an
autoscript. This can be very useful. Use this syntax
file to verify that things work as expected.
|
|
|
- Apply String
Length.SBS This automatically reformats all string variables of
any sav file to the format of the string variable having same name in
a Template.sav file
- Create empty data file with n cases.sbs
(n is supplied by the user at run time)
- Display number
of variables and cases in data file.SBS
- Find number of cases.SBS
(works for weighted and un-weighted files)
- Load data file and
print data values in MsgBox.SBS
- Set data
editor column width to match variable length.sbs
- Split current data file in n random groups.sbs
(n is supplied by the user at run time)
|
|
Top |
|
|
- Get a file name from the user.SBS
- Get
file name from user then define path by macro.SBS
- Get Fiscal Year
from user then run syntax for that year.SBS
- Get user name then
define a usrname macro.SBS
- Variable list demo1.SBS (from SPSS site)
- Variable list demo2.SBS (from SPSS
site)
- Variable list demo3.SBS (from SPSS
site)
|
|
Top |
|
|
- Distribution plot.sbs
- Distribution.SBS
|
|
Top |
|
|
- Empty Designated Draft Output.SBS
|
|
|
|
- Section T-Test or Means or ANOVA
contains a few syntaxes related to Effect Size.
|
|
Top |
|
|
- Change background color of all IGRAPHs in Viewer.SBS
- Change bar colors for each IGRAPH
bar chart with only an x-axis.SBS
- Export
All IGRAPH to Jpeg of a given size.SBS
- Export current IGRAPH to Jpeg of a given size.SBS
- Format IGRAPH.SBS
- Format IGRAPH.SPS (this syntax creates
data, two graphics then calls the above script)
|
|
Top |
|
|
Access:
- Import SPSS using VBA for
ACCESS.mdb This is an MS Access 2000 file. See
instructions inside the GetSPSSvars module.
- Export labels from MS
Access to SPSS.txt This is Visual Basic code.
- Save from SPSS to MS
Access 97 table.SPS (AnswerNet)
Data Editor:
- Export pivot
table data cells to data editor.SBS
Email:
- Save
all attachments of emails to a given folder.SBS (This is an
Outlook VB Script) all emails in a given Outlook folder are
processed)
- Send a document as an attachment to an email.SBS
This SaxBasic script uses Outlook 2000 to send an email to a recipient
with an attachment, the attachment could be an HTML page produced by
SPSS, and spo file or any other documents.
Excel:
- Convert to Excel 5_95
format.SBS SPSS exports to Excel 2.1; this automatically converts
the file to Excel 5/95 format.
- Export tables to a
single excel sheet.sbs
- Export tables to a
single excel sheet v2.sbs This exports then
groups the lines forming a table. Very convenient.
- ExportTablesToSingleExcelSheetV3.sbs
Similar to above script however this one also exports CHARTS and
IGRAPHS.
- ExportTablesToSingleExcelSheetV4.sbs
As an improvement to V3, this one exports all layers of Pivot Tables.
HTML:
- Export all
pivot tables of all spo files to HTM file.SBS
- Export target
items of all spo files to HTM file.SBS (this is an extension of
above script. This one handles IGRAPH in addition to Pivot Table and Charts)
PowerPoint:
- Export Pivot Tables to PowerPoint.SBS
Word or Text file:
- Export Data
Dictionary to text files.sbs (thanks to
Jean-francois Allaire)
- Export Pivot Tables to Word2.sbs
(original by SPSS, modified by John Hendrickx to format tables)
- Export sav file to free format.SBS
- Export visible
output to word via HTML.sbs (here, word
has links to the graphs, graphs are not embedded in the word document)
- Export visible
output to word via HTML v2.sbs (here the
graphs are embedded in the word document)
XML:
- Export content of data editor to XML
format.sbs (with thanks to Tom Diericks. See xml101 for info on the XML format.)
Note: this script and the next one require at least version 3.0
of the Microsoft XML parser. The parser can be downloaded for free
at www.microsoft.com/xml
- Export content of data editor to XML
format v2.sbs (This version is for SPSS version
11 and up). (See the above note)
- Export2Triple-S.SBS
(this script creates a Triple-S v1.2 XML file and related data file
from the current SPSS data file). Thanks to the author Chris Johnson
for sending it.
- Export data from
SPSS to Pulsar Beta 0.16.SBS (with thanks to Alexander Bougakov). This is
based on the above script by Chris Johnson.
- Export spss Output viewer to XML.SBS
|
|
Top |
|
|
- Add extension to all variable names.SBS
- Add the word
"index" at the beginning of all variable labels.SBS
- Add value labels.SBS
- Add value labels using a loop.SBS
- Add variable name at beginning of variable
label.SBS
- Assign variable
label equal to variable name.SBS (can also be done with syntax)
- Capitalise variable
and value labels.sbs
- Define macro calls for each
value label Example2.sbs (This is a
useful programming tool)
- Define macros giving
variable labels.SBS (can also be done with syntax)
- Delete value
labels of all variables.sbs
- Export variable and value labels to txt
files.SBS (thanks to Wouter Egberink for
sending me this code)
- Export
variable name and variable labels to text file.SBS
- Populate
variable with value labels of another variable.SBS (can also be done with syntax)
- Remove pivot table row
and column labels.sbs
- Reverse autorecode.SBS To create a
new string variable containing the value labels of an existing variable (this can also be
done using syntax alone)
- Reverse auto recode10.SBS Use this version for SPSS v10 and over.
|
|
Top |
|
|
- Rename Long to
Short.sbs and Rename
Port Short to Long.sbs. These scripts allow switching between
long and short variable names. Use with this syntax
file.sps. These come from a posting
of Jon Peck.
|
|
Top |
|
|
- Apply autofit.SBS
- Apply Table look to all
output.sbs
- Change graph table text.sbs
- Frequencies footnote.sbs
- Size labels to avoid
line-wrapping.sbs
|
|
Top |
|
|
- Add page breaks at
selected places.SBS (an easy to use script to
automatically insert page breaks before any specified pivot tables). This syntax file shows how to use the
script.
- Break output file into
smaller pieces.SBS (AnswerNet)
- Change label title of
last run procedure.SBS (With thanks to Michael Wexler)
- Create new Output with a given filename and file path.SBS
- Data footer.SBS (sets footer of Output to
name and path of .sav file)
- Delete
statistics and case processing summary.sbs
- Empty designated output
window.sbs
- Extract information from a
text output.SBS (The script is called by this syntax )
- Insert a text
object into the SPSS Viewer.sbs
- Produce a Table of
Content (TOC) listing all pivot tables.SBS
- Remove page breaks.SBS
- Replace
left pane PageTitle by content of right pane.SBS
(Useful to help locate given areas of the output navigator)
- Save current
output windows.SBS The script is called from this
syntax
- Save current output
window-by script.SBS
- Search label in
Output Window.sbs
- Select last table in
current output.SBS
- Write index in output
navigator.SBS
|
|
Top |
|
|
- Applying any script
to all pivot tables .sbs
- Automation of pivotting.SBS
(Examples to learn how to manipulate
layers, columns and rows)
- Autoscript
to format correlation table.sbs (this removes upper diagonal,
highlights significant correlations, moves N's and Sig's to the
Layer's dimension to hide them) With thanks to Ferd Britton)
- Change format means
report.SBS (the script is called by this syntax)
- Change pivot table text.sbs
(This is useful to change column or row labels from English to other languages)
- Change Sig to P.sbs
- Combine mean and SD.SBS (the
script is called by this syntax)
- Create pivot table.sbs
- Create pivot table-ROC.sbs
(the script is called by this
syntax)
- Crop and retain.SBS (with thanks to Mark Baxter)
- Cycling through all layers of a table.sbs
- Define customized
crosstab titles.SBS Note: to avoid asynchronous
problem, the script could be modified to check all documents in the Output window. The
script would then be called only once.
- Delete footnotes of all Pivot Tables.SBS
- Do not display
value labels in pivot tables.SBS
- Exchange rows and
columns of Pivot Table.SBS
- Hide valid and
valid percentage in frequency table.SBS
- Hide a column in pivot
table.SBS
- Highlights significant cells of
all ANOVA tables in Designated Viewer.sbs This is an
example of Applying a script to all (ANOVA) pivot tables in the
Designated Viewer.
- Highlight significant
T-Test cells.sbs
- Left
right or center justify title of all pivot tables.sbs
- Make totals bold.sbs
- Pivoting to each layer of a pivot table.SBS
- Remove percent signs from PivotTable.SBS
- Replacing Empty
Cells of Pivot Tables by user-defined characters.sbs
- Reverse columns order.sbs
- Round frequencies in
crosstab tables.SBS
- Round percentages in
crosstab.SBS
- Set number of decimals
in pivot table.SBS
- Set number decimals of percentages in PivotTable.SBS
- Substitute string in
pivot tables.SBS
- Table widths- with
syntax.SBS (the script is called by this syntax) (Thanks to Jason
Burke for this improved version).
- Traffic light.sbs
- Traffic light fixed 15 and
25.sbs (as above but without dialogs)
- Traffic light with 3 cut
off points.sbs
- Undo percent notation.SBS
- Undo scientific notation.SBS (this
Sub is already included in the Global.SBS file)
- Ungroup a column in a
pivot table.SBS
|
|
Top |
|
|
- Print all spo files in a given
folder.SBS
- Print current
syntax with file path, date, time and page numbers.SBS (It is
convenient to attach that script to a new toolbar button in the script window)
- Print data filename and
path as part of output footer.SBS
- Print options.sbs (this is called by
next syntax)
- Print options.sps
(from AnswerNet)
- Print orientation.SBS
(Add heading, date, time, page numbers to printout)
- Read script parameters
from log file.SBS
- Toggle display of page numbers in Output window.SBS
|
|
Top |
|
|
- Close All Syntax Doc.SBS
- Convert Syntax To Script.sbs
- Find and replace block of text in syntax window.sbs
- Paste text at the end of syntax window.sbs
- Run
Designated Syntax in Batch Mode.SBS I find this very
useful, for convenience associate it to a custom made button on
your syntax toolbar. Click the button when you want the Designated
Syntax to run up to the first error.
- Write syntax file defining variable and value labels.SBS
|
|
Top |
|
|
- Define missing for all
numeric variables.SBS
- Standardize within case.sbs
|
|
Top |
|
|
- Add file date to file names in a given folder.SBS
- Automatically gets
data and output HTML files every hour.SPS
- Automatically
run a script or syntax when SPSS starts.SBS
- Call script B from script A.SBS
- Convert syntax into script
format.SPS (with thanks to Rolf Kjoeller)
- Create new output window.sbs
- Dos.sbs Script to run a Dos
command or Bat file; code by Fabrizio
- Levenshtein Distance
between 2 strings.SBS (this syntax
file explains how to use the script)
- Illustrate windows state.SBS
(how to minimize, maximize a window)
- Multi purpose
script: (run Sub based on syntax call).SBS
- Name data file based
on date read from data file.SBS
- Syntax script.sbs This is
Fabrizio script to circumvent the asynchronous problem. You must ensure that there
are no trailing spaces at the end of the syntax.
- Toggle Output Type.sbs (with
thanks to Karel Asselberghs)
- Terminate syntax with
period.SBS
- Write table of content
of output navigator to text file.SBS
|
|
Top |
|
|
- Combine all .sav files
in the given folder.SBS (only file path and mask is supplied,
script does the rest... The resulting sav file contains a variable
identifying the source file of each case)
- Combine
all sav or text files in given folder.SBS This is a generalization
of the preceding script, this one combines either sav or txt files. A
variable in the final file contains the name of the file where the
case comes from. Of course the DATA LIST commands must be adapted to
each particular situation.
- Convert
all files in folder into other formats.SBS Can convert from
*sav to *.por
*.por to *.sav
*.sav to *.xls
- Create as many sav files as there are txt files.SBS
- Export all
pivot tables (and/or Charts) of all spo files to HTM file.SBS (only
spo files meeting a given path and file mask are processed. One HTM file is created per
SPO file).
- Export target
items of all spo files to HTM file.SBS (this is an extension of
above script. This one handles IGRAPH in addition to Pivot Table and Charts)
- List all files in given
folder.SBS
- Run Same Syntax on 17
Zipped Files.SBS
|
|
Top
|
|

|
|
|
|
| spssrun.exe
This program has been written by Alexis-Michel Mugabushaka
of the University of Kassel, Germany. The program is similar to SPSS Production's
facility. You feed the program with a list of syntax files or a file containing a list of
syntax files. The program runs each syntax one by one and create a separate output
file for each of the syntax file and having the same name as the syntax file. See
also Break Output File
into Smaller Pieces.SBS
|
|
| ViewSav
ViewSav is a Real-Time Codebook for SPSS data files. It
has been written by Karel Asselberghs from the Sociology Department,
University of Amsterdam. He has also 2 other SPSS utilities:CRC32SAV and LISTSAV.
The first one computes checksums for separate parts of a SPSS data file:
file header, dictionnary and data. This enables you to check if these areas of 2 sav files
are identical. The second one list variables and variable labels of a SPSS data file.
(source code included).
|
|