I have multiple categories (Cat1) with many count data rows categorized by sex. I'd like SAS code to sum the count data by sex for each category and test whether there is a significant difference between Male and Female for the sum of counts for each category.
The data look like this:
Cat1 | Sex | Count |
A | M | 1 |
A | F | 0.8 |
A | F | 0.7 |
A | M | 1 |
B | F | 0.9 |
B | F | 1 |
B | M | 0.8 |
B | M | 1 |
C | F | 0.9 |
C | M | 0.7 |
C | F | 1 |
C | M | 1 |
For Cat1 A, is F sum of Counts significantly greater than M sum of Counts? The N for each Sex by Cat1 is over 6 and up to 1200.
I've been using a MWU due to non-normal distributions, but it's restricted to one variable and I don't want to run it for each category separately if I don't have to.
I believe this would be a job for PROC TTEST:
proc ttest data=have;
var count;
class cat1;
run;
Of course, this assumes the variable count is normally distributed, and it probably isn't, but you haven't told us anything about variable COUNT. So, what is the distribution of variable count, and how many data points do you really have?
So perhaps I didn't word my question properly.
How many observations (on average) do you have for each value of CAT1, and how many of those are male and how many of those are female?
@canolden wrote:
That is highly variable. There are 48 levels for the class variable, which t-test doesn't handle. The number of male counts and female counts is different for each level, varying from above 6 counts to hundreds for each sex within level.
My mistake, the code ought to look like this:
proc ttest data=have;
by cat1;
class sex;
var count;
run;
but probably @PGStats has a better solution.
This is how to request a Wilcoxon test for each cat1 value.
proc npar1way data=have wilcoxon plots=none;
by cat1;
class sex;
var count;
output out=stats wilcoxon;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.