## How to perform all combinations of pairwise t-tests with proc multtest?

Solved
Frequent Contributor
Posts: 81

# How to perform all combinations of pairwise t-tests with proc multtest?

I'd like to perform all unique combinations of pairwise Student's t-test comparisons of average length of stay between a family of 31 hospitals, and then output the p-values for each test (with the goal of plotting the ordered p-values to help estimate the # of true null hypotheses according to Schweder and Spjotvoll (1982)).

Is there a simple way to do this with proc multtest without specifiying all possible contrasts with multiple CONTRAST statements? I want to avoid this:

proc multtest data=hospital;

class hospital_name;

test mean(los);

contrast 'A vs B' (-1 1 0 0 ... 0);

contrast 'A vs C' (-1 0 1 0 ... 0);

contrast 'B vs C' (0 -1 1 0 ... 0);

...

contrast 'A vs Z' (1 0 0 0 ... -1);

run;

I've checked the online manual for proc multtest and it isn't terribly helpful.

Accepted Solutions
Solution
‎12-12-2014 10:57 PM
Posts: 5,543

## Re: How to perform all combinations of pairwise t-tests with proc multtest?

Proc GLM has the ability to do all pairwise comparisons and correct p-values for test multiplicity. You will have to do a bit of reformatting of the results as in the following example::

proc glm data=sashelp.baseball plots=none;

class team;

model nRuns = team;

*lsmeans team / pdiff adjust=simulate;       /* Corrected p-values */

lsmeans team / pdiff adjust=t;                      /* Uncorrected p-values */

ods output Diff=teamDiffs LSMeans=teamLSMeans;

run; quit;

proc transpose data=teamDiffs out=teamDiffsLong;

by rowName;

var _:;

run;

proc sql;

create table teamDiffsPList as

select

b.team as team,

c.team as withTeam,

a.COL1 as tProb

from

teamDiffsLong as a inner join

teamLSMeans as b on left(a.rowName) = cats(b.LSMeanNumber) inner join

teamLSMeans as c on a._NAME_ = cats("_", c.LSMeanNumber)

where input(a.rowName, best.) > input(substr(a._NAME_,2), best.)

order by tProb;

quit;

PG

PG

All Replies
Solution
‎12-12-2014 10:57 PM
Posts: 5,543

## Re: How to perform all combinations of pairwise t-tests with proc multtest?

Proc GLM has the ability to do all pairwise comparisons and correct p-values for test multiplicity. You will have to do a bit of reformatting of the results as in the following example::

proc glm data=sashelp.baseball plots=none;

class team;

model nRuns = team;

*lsmeans team / pdiff adjust=simulate;       /* Corrected p-values */

lsmeans team / pdiff adjust=t;                      /* Uncorrected p-values */

ods output Diff=teamDiffs LSMeans=teamLSMeans;

run; quit;

proc transpose data=teamDiffs out=teamDiffsLong;

by rowName;

var _:;

run;

proc sql;

create table teamDiffsPList as

select

b.team as team,

c.team as withTeam,

a.COL1 as tProb

from

teamDiffsLong as a inner join

teamLSMeans as b on left(a.rowName) = cats(b.LSMeanNumber) inner join

teamLSMeans as c on a._NAME_ = cats("_", c.LSMeanNumber)

where input(a.rowName, best.) > input(substr(a._NAME_,2), best.)

order by tProb;

quit;

PG

PG
Frequent Contributor
Posts: 81

## Re: How to perform all combinations of pairwise t-tests with proc multtest?

Fantastic, thank you PGStats!

BTW I also edited the format of the p-values from PVALUEw.d format to 12.8 numerical format to avoid values of "<.001".

🔒 This topic is solved and locked.