Example 2 for PROC GENMOD

This code is also available in: Deutsch Español Français
Difficulty Level
Beginner
Published on :
The script begins by creating a dataset named 'nor' using a DATA step and in-line data (datalines). This dataset contains two variables, 'x' and 'y'. Subsequently, PROC GENMOD is used to fit a model where 'y' is the dependent variable and 'x' is the explanatory variable. The distribution is specified as 'normal' and the link function as 'log'. The OUTPUT statement of PROC GENMOD is used to save predictions and different types of residuals (raw, chi-square, deviance, etc.) into a new dataset named 'Residuals'. Finally, PROC PRINT is used to display the content of the 'Residuals' dataset, allowing for examination of model fit results and residual diagnostics.
Data Analysis

Type : CREATION_INTERNE


The 'nor' dataset is created directly within the script via a DATA step and in-line data (datalines). No external data or SASHELP data is used as initial input.

1 Code Block
DATA STEP Data
Explanation :
This DATA STEP block creates a SAS dataset named 'nor'. It defines two numeric variables, 'x' and 'y', and populates them with values provided directly in the script via the DATALINES clause. This dataset will be used as input for the subsequent statistical procedure.
Copied!
1DATA nor;
2 INPUT x y;
3 DATALINES;
40 5
50 7
60 9
71 7
81 10
91 8
102 11
112 9
123 16
133 13
143 14
154 25
164 24
175 34
185 32
195 30
20;
21 
2 Code Block
PROC GENMOD
Explanation :
This procedure uses PROC GENMOD to fit a generalized linear model to the 'nor' dataset. The variable 'y' is modeled as a function of 'x'. The `dist=normal` parameter specifies a normal distribution for the response, and `link=log` applies a logarithmic link function. The OUTPUT clause is used to generate a new 'Residuals' dataset containing predicted values ('Pred') and various types of residuals for diagnostic analysis of the model.
Copied!
1PROC GENMOD DATA=nor;
2 model y = x / dist = normal
3 link = log;
4 OUTPUT out = Residuals
5 pred = Pred
6 resraw = Resraw
7 reschi = Reschi
8 resdev = Resdev
9 stdreschi = Stdreschi
10 stdresdev = Stdresdev
11 reslik = Reslik;
12RUN;
13 
3 Code Block
PROC PRINT
Explanation :
This block uses PROC PRINT to display the contents of the 'Residuals' dataset created by the previous PROC GENMOD. This allows visualization of model predictions and the various calculated residual measures.
Copied!
1PROC PRINT DATA=Residuals;
2RUN;
3 
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


Related Documentation

Aucune documentation spécifique pour cette catégorie.