Published on :
Statistical INTERNAL_CREATION

Categorical Data Analysis with PROC CATMOD

This code is also available in: Deutsch Español Français English
Awaiting validation
The script begins by creating a 'detergent' dataset from internal data (datalines), representing the results of a brand preference survey. Then, it uses PROC CATMOD to fit two statistical models. The first is a saturated model including all interactions between explanatory variables (water type, prior use, temperature) to predict the preferred brand. The second is a simpler model, considering only the main effects of these same variables, to compare the adjustments.
Data Analysis

Type : INTERNAL_CREATION


Data is created directly within the script via a DATA STEP and a DATALINES statement. It represents an aggregated contingency table where the 'Count' variable serves as a weight.

1 Code Block
DATA STEP Data
Explanation :
This DATA STEP block reads survey data directly from the code (datalines). The variables Softness, Brand, Previous, Temperature, and Count are read. The '@@' option on the INPUT statement indicates that multiple observations can be on the same data line.
Copied!
1DATA detergent;
2 INPUT Softness $ Brand $ Previous $ Temperature $ Count @code_sas_json/8_SAS_Intro_ReadFile_MultiCol_@@.json;
3 DATALINES;
4soft X yes high 19 soft X yes low 57
5soft X no high 29 soft X no low 63
6soft M yes high 29 soft M yes low 49
7soft M no high 27 soft M no low 53
8med X yes high 23 med X yes low 47
9med X no high 33 med X no low 66
10med M yes high 47 med M yes low 55
11med M no high 23 med M no low 50
12hard X yes high 24 hard X yes low 37
13hard X no high 42 hard X no low 68
14hard M yes high 43 hard M yes low 52
15hard M no high 30 hard M no low 42
16;
2 Code Block
PROC CATMOD
Explanation :
This procedure analyzes categorical data. 'WEIGHT Count' specifies that the data is aggregated. 'RESPONSE 1 0' defines the response function. A first saturated model (complete model with all interactions: Softness|Previous|Temperature) is fitted. Then, a simpler second model, with only the main effects, is tested to compare the results. The options '/freq prob' request the display of frequencies and probabilities, and '/clparm noprofile design' request confidence intervals for parameters as well as the model design matrix.
Copied!
1title 'Detergent Preference Study';
2PROC CATMOD DATA=detergent;
3 response 1 0;
4 weight Count;
5 model Brand=Softness|Previous|Temperature / freq prob;
6 title2 'Saturated Model';
7RUN;
8 
9 model Brand=Softness Previous Temperature
10 / clparm noprofile design;
11 title2 'Main-Effects Model';
12RUN;
13QUIT;
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