Python programs
Run Python inside your syntax with BEGIN PROGRAM … END PROGRAM, using the orcstat module to read and change data, run syntax, add tables and charts, and define new procedures.
When to use
Section titled “When to use”- Repetitive work that syntax alone makes tedious: loops over many variables or files, building syntax from the dictionary.
- Calculations OrcStat has no command for, written with NumPy, SciPy or pandas.
- New procedures for your team:
orcstat.register_procedureadds a command that works with SPLIT FILE, FILTER and WEIGHT like a built-in one.
Assumptions
Section titled “Assumptions”- Programs run with your own rights, like any script you run. Read a program before running it.
- Programs suggested by the AI assistant never run. Programs inside a project you open are blocked until you choose Trust programs in Extensions; OrcStat asks again if the programs change.
BEGIN PROGRAM, the code andEND PROGRAM.each start on a line of their own; the code keeps its Python indentation.- Variables, imports and functions stay available to later blocks in the same session.
How to read the output
Section titled “How to read the output”- Text a program prints appears as a log under Python Program; tables and charts it creates appear below it.
- An error names the Python line (counting lines in the syntax file) and the exception, e.g. ZeroDivisionError on line 12.
- Commands after a block run once the program has finished, so they can use procedures it registered.
The API: orcstat.active() and orcstat.dataset(name) return a dataset with names(), column(name), to_pandas(), set_values(name, values, label=, measure=, value_labels=), set_label, set_value_labels, set_measure and delete. orcstat.submit(syntax) runs syntax; orcstat.table(title, rows, columns, values), orcstat.text() and orcstat.chart(vega_lite_spec, title) add output; orcstat.create_dataset(name, data) opens a new dataset. A procedure’s run(proc) gets proc.dataset, proc.variables(), proc.has(), proc.value(), proc.weights() and the same output helpers. Raise orcstat.Error("message") to stop with a message. A partial spss module (Submit, dictionary getters, read cursors) helps converted SPSS programs.
Reporting (APA)
Section titled “Reporting (APA)”Report the analysis the program performed, not the program. For reproducibility, keep the syntax file with the program in it: the journal records the whole block, and the output’s provenance links each table to it.
Syntax:
BEGIN PROGRAM PYTHON3. / import orcstat / ds = orcstat.active() / ds.set_values("ratio", ds.column("income") / ds.column("age")) / orcstat.submit("DESCRIPTIVES ratio.") / END PROGRAM.
This page comes from OrcStat’s built-in help (the same text as in the app’s Help panel). To suggest a change, open an issue.