Published on :
Statistical CREATION_INTERNE

Create Design Matrix for Bayesian Analysis

This code is also available in: Deutsch Español Français
Awaiting validation
The script begins by creating an internal dataset named 'categorical' via a DATA STEP instruction using `datalines`. This dataset contains observations for the variables 'City' (character), 'G' (character), 'x' (numeric), and 'resp' (numeric). Then, the PROC TRANSREG procedure is invoked with the 'design' option to transform the categorical variables 'City' and 'G', as well as their interaction 'City*G', into a design matrix. The `zero=last` coding method is applied. The variables 'x' and 'resp' are designated as identifiers. The resulting output dataset, 'input_mcmc', is created, excluding temporary variables and interaction variables (`_:` and `Int:`). Finally, the PROC PRINT procedure is used to display the contents of the 'input_mcmc' dataset, allowing for a visualization of the generated design matrix.
Data Analysis

Type : CREATION_INTERNE


The source data ('categorical') is created directly within the script using the `datalines` statement, meaning it is integrated into the SAS code itself.

1 Code Block
DATA STEP Data
Explanation :
This DATA STEP block initializes a new dataset named 'categorical'. It defines four variables: 'City' (character), 'G' (character), 'x' (numeric), and 'resp' (numeric). The data for these variables is provided directly in the script via the `datalines` statement, allowing for internal data creation without external dependencies. The `title` statement is also defined here for report outputs.
Copied!
1title 'Create Design Matrix';
2DATA categorical;
3 INPUT City$ G$ x resp;
4 DATALINES;
5Chicago F 69.0 112.5 Chicago F 56.5 84.0
6Chicago M 65.3 98.0 Chicago M 59.8 84.5
7NewYork M 62.8 102.5 NewYork M 63.5 102.5
8NewYork F 57.3 83.0 NewYork M 57.5 85.0
9;
10 
2 Code Block
PROC TRANSREG Data
Explanation :
The TRANSREG procedure is used to generate a design matrix. The input dataset is 'categorical'. The `model` statement specifies that the variables 'city', 'g', and their interaction 'city*g' are treated as class variables, with an effect coding where the last category serves as the reference (`zero=last`). The variables 'x' and 'resp' are included as identifiers. The output dataset, 'input_mcmc', contains the design matrix and is cleaned of unwanted temporary or interaction variables (`drop=_: Int:`).
Copied!
1PROC TRANSREG DATA=categorical design;
2 model class(city g city*g / zero=last);
3 id x resp;
4 OUTPUT out=input_mcmc(drop=_: Int:);
5RUN;
6 
3 Code Block
PROC PRINT
Explanation :
This block uses the PROC PRINT procedure to display the content of the 'input_mcmc' dataset. This allows for a visualization of the design matrix that was generated and prepared by PROC TRANSREG.
Copied!
1PROC PRINT DATA=input_mcmc;
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, NAME: MCMCDES, TITLE: Create Design Matrix for Bayesian Analysis, PRODUCT: STAT, SYSTEM: ALL, PROCS: MCMC, REF: PROC MCMC