## Count Function in SPSS

is there a function similar to Count in SPSS other than the SAS macro %COUNT created by Jim Groeneveld, OCS Biometric Support, the Netherlands in 2008?

here is a video of what Count does in SPSS

1 ACCEPTED SOLUTION

Accepted Solutions

## Re: Count Function in SPSS

You could use the COUNT function or in some cases the COUNTC function.

Example:

``````data have;
do FUN=-4, 4;
do POWER=4, 44;
output;
end;
end;
end;
run;

data want;
set have;
run;``````

The COUNTC function would not work in the above example (but in others where, e.g., all values have length 1) because of the occurrence of digit 4 in values other than 4.

6 REPLIES 6

## Re: Count Function in SPSS

Some of us can't actually view external videos from our work computer (firewall prevents us from doing so). Why don't you just tell us what this function does?

--
Paige Miller

## Re: Count Function in SPSS

I don't really know.  SPSS has this syntax

From what I can tell it does this, for every entry of a 4 in the variable list count.  I will have to confirm by running in SPSS and the code below in SAS to compare the results.
if PSTATE_ADVEN_r=4 and FUN^=4 and POWER^=4 then count4J=1;
else if PSTATE_ADVEN_r^=4 and FUN=4 and POWER^=4 then count4J=1;
else if PSTATE_ADVEN_r^=4 and FUN^=4 and POWER=4 then count4J=1;
else if PSTATE_ADVEN_r=4 and FUN=4 and POWER^=4 then count4J=2;
else if PSTATE_ADVEN_r^=4 and FUN=4 and POWER=4 then count4J=2;
else if PSTATE_ADVEN_r=4 and FUN^=4 and POWER=4 then count4J=2;
else if PSTATE_ADVEN_r=4 and FUN=4 and POWER=4 then count4J=3;

## Re: Count Function in SPSS

I don't really know.  SPSS has this syntax

From what I can tell it does this, for every entry of a 4 in the variable list count.  I will have to confirm by running in SPSS and the code below in SAS to compare the results.
if PSTATE_ADVEN_r=4 and FUN^=4 and POWER^=4 then count4J=1;
else if PSTATE_ADVEN_r^=4 and FUN=4 and POWER^=4 then count4J=1;
else if PSTATE_ADVEN_r^=4 and FUN^=4 and POWER=4 then count4J=1;
else if PSTATE_ADVEN_r=4 and FUN=4 and POWER^=4 then count4J=2;
else if PSTATE_ADVEN_r^=4 and FUN=4 and POWER=4 then count4J=2;
else if PSTATE_ADVEN_r=4 and FUN^=4 and POWER=4 then count4J=2;
else if PSTATE_ADVEN_r=4 and FUN=4 and POWER=4 then count4J=3;

I see that @FreelanceReinh has given you a correct answer. However, for the future, I point out that an answer of "I don't really know" doesn't really advance our understanding and doesn't move us closer to providing help. SPSS syntax doesn't advance our understanding either. Either show us documentation for this COUNT function, or figure it out enough so you can explain.

--
Paige Miller

## Re: Count Function in SPSS

Crappy video link. It is better to point to software document links.

Proc Freq will count the number of observations with each value in the data set.

If you have a SAS install then you should be able to run this code as the SASHELP.CLASS data set is provided by default for training.

```Proc freq data= sashelp.class;
tables sex age;  /*<- this "counts" the values of the variables in one dimension*/
tables sex*age; /* counts in two dimensions, the intersections of the sex and age values*/
tables sex*age / list;  /* displays two dimensions as a single row*/

/* and a different procedure*/
Proc tabulate data=sashelp.class;
class sex age;
tables sex,
age*n;
tables sex*age,
n;
run;```

Procedures Report and Means/Summary can also provide counts. Many analysis procedures will provide a data summary that may show value counts as well.

Note, that SPSS and SAS both have multiple ways to "count" just about anything. The details of what is needed will point to which procedure and/or options may be needed.

## Re: Count Function in SPSS

You could use the COUNT function or in some cases the COUNTC function.

Example:

``````data have;
do FUN=-4, 4;
do POWER=4, 44;
output;
end;
end;
end;
run;

data want;
set have;