![]() | ![]() | ![]() |
Some procedures such as GENMOD, GLMSELECT, PHREG, and others provide options in their CLASS statements (or in other statements) which allow for reference cell coding of CLASS variables and specifying reference levels for the variables. See "Parameterization of Model Effects" in the Shared Concepts and Topics chapter of the SAS/STAT Users Guide. However, many procedures such as GLM, MIXED, LIFEREG, GLIMMIX, and others do not provide this functionality for CLASS variables. These procedures always use the last level (when the levels are sorted in ascending alphanumeric order) of a CLASS variable as the reference level. You can use either of the first two approaches below to make the last level your desired reference level. The final approach shows how you can specify the reference level in a procedure offering the PARAM=REF and REF= options.
To set the reference level of a response variable that is categorical (such as in a logistic regression model), see this usage note.
Consider a CLASS variable, X, with values 0 and 1. By default, these values are arranged in ascending alphanumeric order which results in 1 being the last level, and therefore the reference level. However, if the data are arranged so the value 1 appears before the value 0 as you read down the data set, and if you specify the ORDER=DATA option in the PROC statement, then the levels of X will stay in the order encountered in the data set. Then 0 is last and it becomes the reference level. One way to get the values of X in this order is to sort your data set by X using the DESCENDING option.
For example, in the following data set, the Gender variable has levels F and M. Since F occurs before M in ascending alphanumeric sorting, M will be the reference level by default.
data Heights;
input Family Gender$ Height @@;
datalines;
1 F 67 1 F 66 1 F 64 1 M 71 1 M 72 2 F 63
2 F 63 2 F 67 2 M 69 2 M 68 2 M 70 3 F 63
3 M 64 4 F 67 4 F 66 4 M 67 4 M 67 4 M 69
;
proc mixed data=Heights;
class Gender;
model Height = Gender / solution;
run;
The "Class Level Information" table shows that M is the last level of Gender.
| |||||||||
In the "Solution for Fixed Effects" table, M is the reference level since it is the last level shown and has a zero parameter estimate.
| |||||||||||||||||||||||||||||||||||
However, if you sort the data by descending Gender, then M will precede F in the sorted data set (New). By specifying the ORDER=DATA option, this ordering is preserved and F becomes the reference level.
proc sort data=Heights out=New;
by descending Gender;
run;
proc mixed data=New order=data;
class Gender;
model Height = Gender / solution;
run;
Now, F is the last level in the "Class Level Information" table, and the "Solution for Fixed Effects" table shows that F is the reference level.
| ||||||||||||||||||||||||||||||||||||||||||||
An alternative to reordering or sorting the data is to assign formatted values to the levels such that the last formatted value in ascending alphanumeric order is the desired reference level. Formatted values are used when you specify the ORDER=FORMATTED option in the PROC statement, though this is usually the default when a format exists for the variable.
In the following example, GrazeType=1 is the experimental treatment of interest, so it is desirable to have GrazeType=0 be the reference level. By default, Grazetype=1 would be the reference level since it is the last sorted value.
data graze;
input GrazeType WtGain @@;
datalines;
1 45 1 62 0 94 0 12
1 96 1 128 0 26 0 89
1 120 1 99 0 88 0 96
1 28 1 50 0 85 0 130
1 109 1 115 0 75 0 54
1 39 1 96 0 112 0 69
1 87 1 100 0 104 0 95
1 76 1 80 0 53 0 21
;
By assigning the following formats to the levels, GrazeType=0 has the last formatted value ('Typical'), so it becomes the reference level when the ORDER=FORMATTED option is in effect.
proc format;
value grzfmt
1 = 'Experimental'
0 = 'Typical';
run;
proc glm data=graze order=formatted;
format GrazeType grzfmt.;
class GrazeType;
model WtGain = GrazeType / solution;
run; quit;
| |||||||||||||||||||||||||||||||||
The analysis of GrazeType could be done using PROC GENMOD which provides options for setting the reference level in the CLASS statement. The PARAM=REF option in the CLASS statement selects reference level coding for the levels of GrazeType, and the REF= option specifies the reference level. Note that other procedures may have different syntax for selecting the type of coding and reference level. In the CLASS statement below, the REF="0" option specifies that GrazeType=0 be the reference level.
proc genmod data=graze;
class GrazeType (ref="0" param=ref);
model WtGain = GrazeType;
run;
Reference coding (PARAM=REF) allows specification of a reference level. The default indicator coding (PARAM=GLM) does not. Under the full-rank reference coding, there are only as many parameter estimates as there are degrees of freedom (DF). The binary GrazeType predictor has two levels and one DF, so a parameter estimate for the reference level is not listed but is zero under this coding as it is under indicator coding. The dummy variable used in the design matrix is shown in the Class Level Information table. It's reference (zero) level corresponds to GrazeType=0. The parameter estimate for the nonreference level, GrazeType=1, is shown indicating that GrazeType=0 was used as the reference level.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
If formats are used, specify the formatted value of the reference level in the REF= option.
proc genmod data=graze;
format GrazeType grzfmt.;
class GrazeType (ref="Typical" param=ref);
model WtGain = GrazeType;
run;
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The standard errors in the GENMOD results differ from those in the GLM results because a different estimation method is used.
| Product Family | Product | System | SAS Release | |
| Reported | Fixed* | |||
| SAS System | SAS/STAT | z/OS | ||
| OpenVMS VAX | ||||
| Microsoft® Windows® for 64-Bit Itanium-based Systems | ||||
| Microsoft Windows Server 2003 Datacenter 64-bit Edition | ||||
| Microsoft Windows Server 2003 Enterprise 64-bit Edition | ||||
| Microsoft Windows XP 64-bit Edition | ||||
| Microsoft® Windows® for x64 | ||||
| OS/2 | ||||
| Microsoft Windows 95/98 | ||||
| Microsoft Windows 2000 Advanced Server | ||||
| Microsoft Windows 2000 Datacenter Server | ||||
| Microsoft Windows 2000 Server | ||||
| Microsoft Windows 2000 Professional | ||||
| Microsoft Windows NT Workstation | ||||
| Microsoft Windows Server 2003 Datacenter Edition | ||||
| Microsoft Windows Server 2003 Enterprise Edition | ||||
| Microsoft Windows Server 2003 Standard Edition | ||||
| Microsoft Windows Server 2008 | ||||
| Microsoft Windows XP Professional | ||||
| Windows Millennium Edition (Me) | ||||
| Windows Vista | ||||
| 64-bit Enabled AIX | ||||
| 64-bit Enabled HP-UX | ||||
| 64-bit Enabled Solaris | ||||
| ABI+ for Intel Architecture | ||||
| AIX | ||||
| HP-UX | ||||
| HP-UX IPF | ||||
| IRIX | ||||
| Linux | ||||
| Linux for x64 | ||||
| Linux on Itanium | ||||
| OpenVMS Alpha | ||||
| OpenVMS on HP Integrity | ||||
| Solaris | ||||
| Solaris for x64 | ||||
| Tru64 UNIX | ||||
| Type: | Usage Note |
| Priority: | |
| Topic: | Analytics ==> Analysis of Variance Analytics ==> Categorical Data Analysis Analytics ==> Mixed Models Analytics SAS Reference ==> Procedures ==> ANOVA SAS Reference ==> Procedures ==> CATMOD SAS Reference ==> Procedures ==> GAM SAS Reference ==> Procedures ==> GENMOD SAS Reference ==> Procedures ==> GLIMMIX SAS Reference ==> Procedures ==> GLM SAS Reference ==> Procedures ==> GLMMOD SAS Reference ==> Procedures ==> GLMPOWER SAS Reference ==> Procedures ==> GLMSELECT SAS Reference ==> Procedures ==> HPMIXED SAS Reference ==> Procedures ==> LIFEREG SAS Reference ==> Procedures ==> LOGISTIC SAS Reference ==> Procedures ==> MIXED SAS Reference ==> Procedures ==> PHREG SAS Reference ==> Procedures ==> PLS SAS Reference ==> Procedures ==> PROBIT SAS Reference ==> Procedures ==> QUANTREG SAS Reference ==> Procedures ==> ROBUSTREG SAS Reference ==> Procedures ==> NESTED SAS Reference ==> Procedures ==> SURVEYLOGISTIC SAS Reference ==> Procedures ==> SURVEYREG SAS Reference ==> Procedures ==> TRANSREG |
| Date Modified: | 2009-09-25 10:01:23 |
| Date Created: | 2009-09-07 11:11:11 |



