Programming the statistical procedures from SAS

Question regarding contrast statement

Reply
New Contributor
Posts: 3

Question regarding contrast statement

I am just wondering if there is a mistake with the attached code since the class level information for sex is female = 0 and male = 1, the first part of the code is contrasting different groups in males and the value used was zero. Should it not be 1 instead?. Can some explain how the contrast statement works in an interaction?

Super User
Posts: 5,256

Re: Question regarding contrast statement

Please don't attach office documents.
If it's code just paste it into the code editor in the post.
Data never sleeps
New Contributor
Posts: 3

Re: Question regarding contrast statement

 
Class Level Information
Class Value Design Variables
group A 1 0
          B 0 1
          C 0 0
sex Female 0
      Male 1
 
proc phreg data=sasuser.ami;
class group(ref='C') sex(ref='Female') / param=ref order=internal;
model days*status(0) = group sex group*sex / ties=Efron;
* Contrasts among groups for SEX=Male and SEX=Female. *;
contrast 'AvsB sex=Male' group 1 -1 sex 0 group*sex 1 -1 / estimate=exp e;
contrast 'AvsC sex=Male' group 1 0 sex 0 group*sex 1 0 / estimate=exp e;
contrast 'BvsC sex=Male' group 0 1 sex 0 group*sex 0 1 / estimate=exp e;
contrast 'AvsB sex=Female' group 1 -1 sex 0 group*sex 0 0 / estimate=exp e;
contrast 'AvsC sex=Female' group 1 0 sex 0 group*sex 0 0 / estimate=exp e;
contrast 'BvsC sex=Female' group 0 1 sex 0 group*sex 0 0 / estimate=exp e;
* Contrasts among sexes for groups A, B, and C. *;
contrast 'Male vs Female group=A' group 0 0 sex 1 group*sex 1 0 /
estimate=exp e;
contrast 'Male vs Female group=B' group 0 0 sex 1 group*sex 0 1 /
estimate=exp e;
contrast 'Male vs Female group=C' group 0 0 sex 1 group*sex 0 0 /
estimate=exp e;
* Contrast that cannot be replicated with a HAZARDRATIO statement. This *;
* contrast compares group A with the average of groups B and C for males. *;
contrast 'A vs (B+C)/2 at sex=Male' group 1 -0.5 sex 0 group*sex 1 -0.5 /
estimate=exp e;
run;
SAS Employee
Posts: 228

Re: Question regarding contrast statement

[ Edited ]

If you want to make simple pairwise comparisons, it is always easiest to use the LSMEANS, LSMESTIMATE, or SLICE statement since this allows you to avoid the always error-prone process of determining contrast coefficients for the CONTRAST or ESTIMATE statement. This is discussed and illustrated in detail in this note. For a model with interaction, you can use the SLICE statement to simplify getting your comparisons. 

New Contributor
Posts: 3

Re: Question regarding contrast statement

Hi all,

 

I am testing an interaction between two categorical variables; the first variable has 5 levels and the other has 4. However, I just want to contrast some levels of this interaction and obtain an overall p-value for those interaction terms being contrasted. Is that possible? if so how?

 

Any help would be appreciated.

SAS Employee
Posts: 228

Re: Question regarding contrast statement

The note I referred to shows exactly the sort of comparisons you seem to want in your original post. Please look over the examples. The SLICE, LSMEANS, and LSMESTIMATE statements work the same way in any modeling procedure that supports them.

 

slice group*sex / sliceby=sex; 

and

slice group*sex / sliceby=group;

 

Note that you need to use PARAM=GLM (not REF) in the CLASS statement to use SLICE, LSMEANS, or LSMESTIMATE.  See the documentation of the SLICE and LSMEANS statements in your modeling procedure to see the additional options that are available.

Ask a Question
Discussion stats
  • 5 replies
  • 159 views
  • 6 likes
  • 3 in conversation