Published on :
Statistical CREATION_INTERNE

Example 4 for PROC GLM - Analysis of Covariance

This code is also available in: Deutsch Español Français
Awaiting validation
The script first creates a 'DrugTest' dataset containing the effect of three drugs (A, D, F). Then, it uses PROC GLM to model the effect of the drug and the pre-treatment measurement on the post-treatment measurement. Least squares means (lsmeans) are calculated to compare the effects of the drugs and are saved in the 'adjmeans' table, which is then displayed. Finally, the script uses ODS Graphics and a second PROC GLM pass to visualize the adjusted covariance analysis model, including a graph of means with confidence limits.
Data Analysis

Type : CREATION_INTERNE


The data is created directly within the script using a DATA step and 'datalines'.

1 Code Block
DATA STEP Data
Explanation :
This block creates the 'DrugTest' dataset by reading embedded data via 'datalines'. It defines three variables: 'Drug' (character), 'PreTreatment' (numeric), and 'PostTreatment' (numeric).
Copied!
1DATA DrugTest;
2 INPUT Drug $ PreTreatment PostTreatment;
3 DATALINES;
4A 11 6 A 8 0 A 5 2 A 14 8 A 19 11
5A 6 4 A 10 13 A 6 1 A 11 8 A 3 0
6D 6 0 D 6 2 D 7 3 D 8 1 D 18 18
7D 8 4 D 19 14 D 8 9 D 5 1 D 15 9
8F 16 13 F 13 10 F 11 18 F 9 5 F 21 23
9F 16 12 F 12 5 F 12 16 F 7 1 F 12 20
10;
11RUN;
2 Code Block
PROC GLM Data
Explanation :
This General Linear Model (GLM) procedure performs a covariance analysis. 'PostTreatment' is the dependent variable, modeled by the effect of 'Drug' (class variable) and 'PreTreatment' (covariate). The 'solution' option requests the display of parameter estimates. The 'lsmeans' statement calculates the adjusted means for each 'Drug' level, with standard errors, p-values for differences, the covariance matrix, and saves the results to a new dataset named 'adjmeans'.
Copied!
1PROC GLM DATA=DrugTest;
2 class Drug;
3 model PostTreatment = Drug PreTreatment / solution;
4 lsmeans Drug / stderr pdiff cov out=adjmeans;
5RUN;
3 Code Block
PROC PRINT
Explanation :
This code block displays the content of the 'adjmeans' dataset, which was created by the 'lsmeans' statement in the previous PROC GLM step.
Copied!
1PROC PRINT DATA=adjmeans;
2RUN;
4 Code Block
PROC GLM
Explanation :
This block activates ODS graphics output to visualize the results. The GLM procedure is called again, this time with the 'plot=meanplot(cl)' option to generate a graph of adjusted means with confidence limits for the 'Drug' variable. The 'lsmeans' statement with the 'pdiff' option calculates pairwise differences between least squares means. ODS Graphics is then deactivated.
Copied!
1ods graphics on;
2 
3PROC GLM DATA=DrugTest plot=meanplot(cl);
4 class Drug;
5 model PostTreatment = Drug PreTreatment;
6 lsmeans Drug / pdiff;
7RUN;
8 
9ods graphics off;
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 : S A S S A M P L E L I B R A R Y