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
Hello @Zad,
You could use the COUNT function or in some cases the COUNTC function.
Example:
data have;
do PSTATE_ADVEN_r=0.4, 4;
do FUN=-4, 4;
do POWER=4, 44;
output;
end;
end;
end;
run;
data want;
set have;
n4=count(catx('||','#',PSTATE_ADVEN_r,FUN,POWER,'#'),'|4|');
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.
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?
I don't really know. SPSS has this syntax
COUNT Count4J=PSTATE_ADVEN_r FUN POWER(4).
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;
@Zad wrote:
I don't really know. SPSS has this syntax
COUNT Count4J=PSTATE_ADVEN_r FUN POWER(4).
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.
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.
Hello @Zad,
You could use the COUNT function or in some cases the COUNTC function.
Example:
data have;
do PSTATE_ADVEN_r=0.4, 4;
do FUN=-4, 4;
do POWER=4, 44;
output;
end;
end;
end;
run;
data want;
set have;
n4=count(catx('||','#',PSTATE_ADVEN_r,FUN,POWER,'#'),'|4|');
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.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.