/* Various useful pieces of SAS information for: */ /* constructing indicator variables */ /* and fitting multiple regression models */ /* the file light.dat contains three columns of data from the */ /* described in chapter 9, case 1. */ /* the first variable is the number of flowers, /* the second is the timing treatment: E for early and L for late, /* the third is the light level */ /* the first issue is to tell SAS not to expect a number when it reads /* the timing treatment. We do this by putting a $ after the /* variable name on the input command. This tells SAS that the /* previous variable is a character variable, not a numeric variable */ data light; infile '../data/light.dat'; input flowers time $ light; /* there are two ways to construct an indicator variable, X2, that is /* 1 with time is equal to "E" and 0 otherwise. The easy to understand /* way uses if then and else commands */ if (time = "E") then X2 = 1; else X2 = 0; /* a short cut if you are doing many of these is to know that "True" /* is 1 in SAS and "false" is 0, so we can use logical operations */ X2a = (time = "E"); /* Finally, create a variable for the interaction of light and time */ /* X3 contains 0 if the timing group is the L group (because X2 = 0 then) */ /* and the light level if the timing group is the E group */ /* This variable is used to test whether the two timing groups have */ /* the same slopes and estimate the difference in slopes */ X3 = X2 * light; proc print; title 'Data and constructed variables for light study'; run; /* we can fit models for multiple regressions by listing multiple */ /* variables in the model command */ /* the sas output includes the parameter estimates and their s.e.'s */ /* remember the 'changing this without changing any other ' */ /* interpretation of these coefficients */ /* the model SS (for all terms, i.e. comparing the equal means model */ /* to the specified model */ /* the error SS (for the specified model) */ /* and a variety of other possibly useful SS to save you time */ /* For example, the type I SS are answers to the question: */ /* If I add this variable to a model that contains only those */ /* variables to the left of my in the model command, by how much */ /* is the SSE reduced? */ /* Without any variables, the model is the equal means model */ /* So, in the second GLM with light, X2 and X3, */ /* the type I SS for light is the reduction in SS adding light */ /* I.e. the difference SSE(light) - SSE(equal) /* The type I SS for X2 adds X2 to the light model */ /* I.e. the difference SSE(light, X2) - SSE(light) /* the type I SS for X3 adds X3 to the light, X2 model */ /* I.e. the difference SSE(light, X2, X3) - SSE(light, X2) */ proc glm; model flowers = light X2; title 'Model with no interaction'; run; proc glm; model flowers = light X2 X3; title 'Model with interaction of light and time'; run; /* it is also possible to have SAS create the 0/1 indicator variables */ /* automatically. This is what the CLASS statement does */ /* compare the output from the following to the output from the above */ /* the /solution option is required to get estimates when a class */ /* statement used */ proc glm; class time; model flowers = light time light*time /solution; title 'Model with interaction of light and time, using automatic vars'; run;