SPSS
Not yet tested on a real installation — tell us how it went. The code follows the vendor's documentation. Write to support@taskbeacon.io.
Uses the SPSS Statistics Python 3 integration (BEGIN PROGRAM PYTHON3).
The code
This is the code the Code tab generates (with start, errors and rows ticked). In the app it already contains your job's own address.
* --- TaskBeacon: SPSS Statistics with the Python 3 integration ---.
BEGIN PROGRAM PYTHON3.
import json, urllib.request
import spss
TB = "https://taskbeacon.io/ping/your-job-id"
def tb_ping(path="", data=None):
body = json.dumps(data).encode() if data else None
req = urllib.request.Request(TB + path, data=body, headers={"Content-Type": "application/json"})
try:
urllib.request.urlopen(req, timeout=10)
except Exception as e:
print("TaskBeacon ping failed:", e)
tb_ping("/start")
try:
spss.Submit(r"""
* --- your syntax here (the example data: replace it, e.g. GET FILE='C:\data\sales.sav'.) ---.
DATA LIST FREE / amount.
BEGIN DATA
12.5 7 3
END DATA.
""")
except spss.SpssError as e:
tb_ping("/fail", {"error": str(e)[:200]})
raise
tb_ping("", {"rows": spss.GetCaseCount()})
END PROGRAM.How it works
The code pings /start when the script begins, the plain address with the row count when it ends well, and /fail when it fails, with the error message.
Untick options on the Code tab to leave parts out. See what can be reported.
Run SPSS syntax on a schedule
SPSS Statistics runs syntax unattended as a production job: in SPSS open Utilities → Production Facility, add your .sps file (with the TaskBeacon block at its top) and save the job as a .spj file. Then start it from the command line with --production … silent, so it doesn't wait for input (IBM's page also lists the switch as -production):
"C:\Program Files\IBM\SPSS Statistics\stats.exe" --production "C:\jobs\sales.spj" silent
Put that line in Task Scheduler (Action: Start a program). The folder of stats.exe depends on your version. IBM documents these switches under "Command line options" (docs for version 23, from about 2015; check the docs of your version).
Why the exit code isn't enough
A production job can end without a visible failure while a command in it went wrong; the details are in the job's output file, which nobody opens when all is quiet.
The code above runs your syntax through spss.Submit inside Python, so an SPSS error raises spss.SpssError, which sends /fail with the message.
Report the row count
At the end the code sends spss.GetCaseCount(), the number of cases in the active dataset. Activate the dataset you care about before that line.
Common problems
- BEGIN PROGRAM fails. The Python 3 integration must be installed and turned on (in recent versions it comes with SPSS Statistics).
- Paths in the syntax. Use full paths in
GET FILE; the working folder of a production job is not your syntax folder. - Network drives. A task that runs while you are logged out doesn't see mapped drive letters; use UNC paths.
Use cases: Get an alert when an SPSS Statistics production job fails. More questions: FAQ.