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!
title 'Create Design Matrix';
data categorical;
input City$ G$ x resp;
datalines;
Chicago F 69.0 112.5 Chicago F 56.5 84.0
Chicago M 65.3 98.0 Chicago M 59.8 84.5
NewYork M 62.8 102.5 NewYork M 63.5 102.5
NewYork F 57.3 83.0 NewYork M 57.5 85.0
;
1
title 'Create Design Matrix';
2
DATA categorical;
3
INPUT City$ G$ x resp;
4
DATALINES;
5
Chicago F 69.0112.5 Chicago F 56.584.0
6
Chicago M 65.398.0 Chicago M 59.884.5
7
NewYork M 62.8102.5 NewYork M 63.5102.5
8
NewYork F 57.383.0 NewYork M 57.585.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!
proc transreg data=categorical design;
model class(city g city*g / zero=last);
id x resp;
output out=input_mcmc(drop=_: Int:);
run;
1
PROC TRANSREGDATA=categorical design;
2
model class(city g city*g / zero=last);
3
id x resp;
4
OUTPUT out=input_mcmc(drop=_: Int:);
5
RUN;
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!
proc print data=input_mcmc;
run;
1
PROC PRINTDATA=input_mcmc;
2
RUN;
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
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.