SPSS Statistics

SPSS Statistics

Your hub for statistical analysis, data management, and data documentation. Connect, learn, and share with your peers! 

 View Only
  • 1.  How to access the number of active cases after filtering?

    Posted Thu February 09, 2023 04:47 AM
    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 ?






  • 2.  RE: How to access the number of active cases after filtering?

    Posted Thu February 09, 2023 09:44 AM
    There is no  built-in property for this as the number is dynamic.  It would require a data pass.  One way to do that would be to use OMS to capture a table from a procedure that contains this while suppressing that output from the Viewer.  Or you could pass the data yourself using the spssdata module or the spss module.





    --





  • 3.  RE: How to access the number of active cases after filtering?

    Posted Thu February 09, 2023 09:45 AM

    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
    ------------------------------



  • 4.  RE: How to access the number of active cases after filtering?

    Posted Fri February 10, 2023 04:24 AM
    Hi Rick, 

    this is very nice. Thanks a lot.