Hi. I haven't had a lot of time this morning to work on this, but I know the Cursor class honors FILTER. For example:
** Test data.
DATA LIST FREE /var1 (F) var2 (A2) var3 (F).
BEGIN DATA
11 ab 13
21 cd 23
31 ef 33
END DATA.
** Filter.
USE ALL.
COMPUTE filter_$=(var1 < 31).
VARIABLE LABELS filter_$ 'var1 < 31 (FILTER)'.
VALUE LABELS filter_$ 0 'Not Selected' 1 'Selected'.
FORMATS filter_$ (f1.0).
FILTER BY filter_$.
EXECUTE.
*Find N Cases.
BEGIN PROGRAM PYTHON3.
import spss
i=[0]
N=0
dataCursor=spss.Cursor(i)
oneVar=dataCursor.fetchall()
for i in oneVar:
N=N+1
dataCursor.close()
print("Number of filtered cases:")
print(N)
END PROGRAM.
------------------------------
Rick Marcantonio
Quality Assurance
IBM
------------------------------
Original Message:
Sent: Thu February 09, 2023 04:46 AM
From: Frank Watzl
Subject: How to access the number of active cases after filtering?
spss.GetCaseCount() returns the number of all cases, regardless of a filter being active.
How can I assign the number of active cases to a Python variable, after filter by my_filter_var ?