OK, here is an example I think might work:
output close all.
dataset close all.
GET FILE="your file here".
preserve.
set printback none.
** Be sure to change the file location for the following text file.
oms select logs /destination format=text outfile="/Users/rick/tmp/list.txt".
do if $casenum=1.
DO REPEAT existVar=v1 v3 to v5 v7 v8 to v10.
print / existvar.
END REPEAT.
end if.
execute.
omsend.
restore.
begin program python3.
import spss
** Now read that same file back into Python, making a list out of it.
my_file = open("/Users/rick/tmp/list.txt", "r")
myvariables = my_file.read()
varlist=[]
varcount=spss.GetVariableCount()
for i in range(varcount):
v=spss.GetVariableName(i)
if v in myvariables:
print("""
OMS
/SELECT TABLES
/IF COMMANDS=['CSTABULATE'] INSTANCES=[LAST]
/EXCEPTIF SUBTYPE=['NOTES']
/DESTINATION FORMAT=XLSX OUTFILE="...\%s_cstab_output.xlsx"
/NOWARN.
MISSING VALUES %s (66 thru 99).
CSTABULATE
/PLAN FILE='...\weighing2.csaplan'
/TABLES VARIABLES=%s
/CELLS TABLEPCT
/STATISTICS SE CV CIN(95) COUNT
/MISSING SCOPE=TABLE CLASSMISSING=EXCLUDE.
EXECUTE.
OMSEND.
"""%(v,v,v))
end program.
Substitute your variable list where I have << >> in "DO REPEAT existVar=<<v1 v3 to v5 v7 v8 to v10>>."
The Python script can be easily changed to submit these commands but first try a sample and print it to make sure it is doing what you want.
Let me know if any problems.
------------------------------
Rick Marcantonio
Quality Assurance
IBM
------------------------------
Original Message:
Sent: Sun February 06, 2022 01:19 PM
From: Thomas Tun
Subject: Analysis of Survey data: How to calculate the same statistical method for numerous variables
Hello,
We, the survey team, are producing results for >200 variables (e.g. A1 to A20, B1A to B1Z, Z1_new to Z10_new, etc.) using the same statistical analysis (CSTABULATE) and OMS to produce >200 output files. In the example below, we analyze the C8 variable.
OMS
/SELECT TABLES
/IF COMMANDS = ['CSTABULATE']
INSTANCES = [LAST]
/EXCEPTIF SUBTYPE = ['NOTES']
/DESTINATION FORMAT = XLSX
OUTFILE = "...\C8_cstab_output.xlsx"
/NOWARN.
MISSING VALUES C8 (66 thru 99).
CSTABULATE
/PLAN FILE='...\weighing2.csaplan'
/TABLES VARIABLES=C8
/CELLS TABLEPCT
/STATISTICS SE CV CIN(95) COUNT
/MISSING SCOPE=TABLE CLASSMISSING=EXCLUDE.
EXECUTE.
OMSEND.
Currently, we are tediously replacing one variable after another variable and click run to get an output file. We are wondering how can we write extra lines in syntax (such as loop, repeat, etc.) that will replace another variable in the place of C8 and run all variables at a run and produce >200 output files, instead of running one by one?
Thank you very much in advance.
------------------------------
Thomas
------------------------------
#SPSSStatistics