The script begins by creating a dataset named 'twoway' using datalines statements. This dataset contains three variables: A and B, which are classification variables (categorical), and Y, which is the dependent variable (quantitative). Next, the script executes PROC GLM to fit a general linear model. This model includes the main effects of variables A and B, as well as their interaction term A*B, to evaluate how the effect of one variable changes depending on the levels of the other. Finally, the LSMEANS statement is used with the SLICE=B option to examine the simple effects of variable A at each distinct level of variable B. This allows for understanding interactions by detailing the impact of A when B is held constant at a given level, and vice-versa.
Data Analysis
Type : INTERNAL_CREATION
The data used for the analysis is generated directly within the SAS script via a DATA STEP statement with datalines. The 'twoway' dataset is thus created with predefined observations.
1 Code Block
DATA STEP Data
Explanation : This DATA STEP block creates a temporary dataset named 'twoway'. It defines three variables (A, B, and Y) and uses the DATALINES statement to populate the dataset with values specified directly in the script. The ' @code_sas/16.4'.sas at the end of the INPUT statement instructs SAS to remain on the same data line to read the next observation if available.
Explanation : This block executes PROC GLM on the 'twoway' dataset. The CLASS statement declares variables A and B as categorical variables. The MODEL statement specifies that the dependent variable Y is modeled as a function of the main effects of A and B, as well as their interaction A*B. 'run;' terminates this procedure step.
Copied!
proc glm data=twoway;
class A B;
model Y = A B A*B;
run;
1
PROC GLMDATA=twoway;
2
class A B;
3
model Y = A B A*B;
4
RUN;
3 Code Block
PROC GLM (LSMEANS statement)
Explanation : This LSMEANS statement is a sub-statement of the previous PROC GLM. It requests the calculation of least squares means for the A*B interaction term. The SLICE=B option is crucial: it instructs SAS to analyze the simple effects of A for each level of B, which is a standard method for decomposing and interpreting a significant interaction.
Copied!
lsmeans A*B / slice=B;
run;
1
lsmeans A*B / slice=B;
2
RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : SAS SAMPLE LIBRARY, NAME: GLMDE5, TITLE: Details Example 5 for PROC GLM, PRODUCT: STAT
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.