Count cases

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Count cases

Jade B
I am trying to write a syntax script which runs different anayses
depending on how many cases are selected.

e.g.

If n < 20, do wilcox

If n >= 20, do t-test

But I am unable to figure out if there is a command which can tell me how
many cases are selected.

Any help would be greately appreciated.
Jade

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Count cases

Jon K Peck
The answer depends on whether you are filtering cases or not.  The command SHOW N will display the number of cases in the file, but it does not account for filtering.  You can capture this value programmatically by using OMS to create a dataset containing the table.  It would be easiest to put this logic in Python code.  E.g.,

begin program.
import spss, spssaux
nofcases = spssaux.getShow("N")
if nofcases < 20:
  spss.Submit(<"some syntax">)
else:
  spss.Submit(<"some other syntax">)
end program.

If you need to count cases subject to a filter, you would need to do AGGREGATE or some other procedure that passes the data and produces a case count.

HTH,


Jon Peck
Senior Software Engineer, IBM
[hidden email]
312-651-3435




From:        Jade B <[hidden email]>
To:        [hidden email]
Date:        11/21/2010 10:41 PM
Subject:        [SPSSX-L] Count cases
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




I am trying to write a syntax script which runs different anayses
depending on how many cases are selected.

e.g.

If n < 20, do wilcox

If n >= 20, do t-test

But I am unable to figure out if there is a command which can tell me how
many cases are selected.

Any help would be greately appreciated.
Jade

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

Reply | Threaded
Open this post in threaded view
|

Re: Count cases

Ruben Geert van den Berg
I thought something like below would work but, indeed, the case filter is ignored.

Perhaps you could 1) name your dataset 2) copy your dataset (scratch copy) 3) delete unfiltered cases (SELECT IF) 4) run the case count dependent procedure(s) 4) close the scratch copy, activate the original dataset and restart at 1). Doesn't sound too complicated.

Best,

Ruben

*So this clearly does NOT work.

data list free/id.
begin data
1 2 3 4 5 6 7 8 9 10
end data.

compute filter_1=id gt 3.
compute filter_2=id gt 6.
exe.

begin program.
import spss
spss.Submit("filter by filter_1.")
print spss.GetCaseCount()
end program.


Date: Mon, 22 Nov 2010 08:18:32 -0700
From: [hidden email]
Subject: Re: Count cases
To: [hidden email]

The answer depends on whether you are filtering cases or not.  The command SHOW N will display the number of cases in the file, but it does not account for filtering.  You can capture this value programmatically by using OMS to create a dataset containing the table.  It would be easiest to put this logic in Python code.  E.g.,

begin program.
import spss, spssaux
nofcases = spssaux.getShow("N")
if nofcases < 20:
  spss.Submit(<"some syntax">)
else:
  spss.Submit(<"some other syntax">)
end program.

If you need to count cases subject to a filter, you would need to do AGGREGATE or some other procedure that passes the data and produces a case count.

HTH,


Jon Peck
Senior Software Engineer, IBM
[hidden email]
312-651-3435




From:        Jade B <[hidden email]>
To:        [hidden email]
Date:        11/21/2010 10:41 PM
Subject:        [SPSSX-L] Count cases
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




I am trying to write a syntax script which runs different anayses
depending on how many cases are selected.

e.g.

If n < 20, do wilcox

If n >= 20, do t-test

But I am unable to figure out if there is a command which can tell me how
many cases are selected.

Any help would be greately appreciated.
Jade

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD