## count valid N

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

silaarts
Posts: 1
Joined: Fri Sep 13, 2013 8:29 am

### count valid N

I want to count 'a variabele'. That is, I want to count how many missing there are in one variabele.
Of course, this is easy by using 'frequencies variables age' (for exmaple).
However, I want a syntax that can say a smuch as 'if frequencies variables >99 then analysis....'.
Hence, I only want to conduct an analysis if the N of the sample (i.e. the frequences without the missings) is at least 100.

I think I should use lag or loop. However, I can not get SPSS to count for me in one variable and provide me the total of that variabele in, for example, another variabele.
If so, then I could use 'If (var1 >99) then regression...'.
statman
Posts: 2756
Joined: Tue Jun 12, 2007 12:08 pm
Location: Florida, USA

### Re: count valid N

If clear then can't do directly but might with a macro (can't help there) but look into the OMS function whereby you can run an analysis, e.g., FREQ and output to a dataset then read a data value from the dataset as a check to run another analysis on a different dataset
See the note below

Statman
Statistical Services
pythonforspss.org
Posts: 116
Joined: Sat Oct 06, 2012 6:21 am

### Re: count valid N

You could do it without Python but that would be very clumsy. For a syntax demonstration of how to do it efficiently, see this tutorial: http://www.spss-tutorials.com/restrict- ... m-valid-n/.
Last edited by pythonforspss.org on Fri Nov 15, 2013 9:10 am, edited 2 times in total.
Kind regards,

Ruben Geert van den Berg
http://www.spss-tutorials.com
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

### Re: count valid N

you can simply do this in 2-3 steps I think:

a) compute a new variable that holds 1 if a case is not missing (if vara > .01 or whatever is applicable in your situation)
b) using aggregate, create a sum score for that entire variable (e.g.: sum_var1)
c) use if (sum_var1 > 99) ..... etc.
pythonforspss.org
Posts: 116
Joined: Sat Oct 06, 2012 6:21 am

### Re: count valid N

@Gutnre: please provide us with a working syntax example of what you mean.
Kind regards,

Ruben Geert van den Berg
http://www.spss-tutorials.com
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

### Re: count valid N

I thought it was pretty clear but ok.

Let's assume the variable that should have at least 99 non missing is called var1.
Easiest I can think of is:

recode var1 (sysmis = 99999).

if (var1 = 99999) temp1 = 1.
execute.

aggregate /outfile=*
/tempsum = sum(temp1).

delete variables temp1.

Then it depends on what analysis should follow, but now you have a variable that shows the number of non-missings in a variable.
pythonforspss.org
Posts: 116
Joined: Sat Oct 06, 2012 6:21 am

### Re: count valid N

The OP was asking for a FREQUENCIES command that automatically excludes variables with less than N valid cases. How does your code accomplish that?
Kind regards,

Ruben Geert van den Berg
http://www.spss-tutorials.com
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

### Re: count valid N

recode var1 (sysmis = 99999).

if (var1 = 99999) temp1 = 1.
execute.

aggregate /outfile=*
/tempsum = sum(temp1).

aggregate /outfile=*
/ntot = N(tempsum).

compute validn = ntot - tempsum.
execute.

Then you have a variable with the valid N.
I think that is what was asked for?
pythonforspss.org
Posts: 116
Joined: Sat Oct 06, 2012 6:21 am

### Re: count valid N

I believe the OP was asking for a FREQUENCIES command that automatically excludes variables with less than N valid cases. So where are the frequencies tables?
Kind regards,

Ruben Geert van den Berg
http://www.spss-tutorials.com
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

### Re: count valid N

Well let's let OP clarify what he/she wants exactly.
nyb10
Posts: 1
Joined: Thu Nov 07, 2013 8:16 pm

### Re: count valid N

I just joined the forum to find a solution to this exact problem: How to exclude cases with a count of less than N before running frequencies.

Alternatively, is it possible to select cases based on in-variable counts?
pythonforspss.org
Posts: 116
Joined: Sat Oct 06, 2012 6:21 am

### Re: count valid N

"How to exclude cases with a count of less than N before running frequencies?"