Raw data is directly integrated into the script via a `datalines` statement, forming the 'heights' dataset. This is then transformed into 'input' for MCMC analysis.
1 Code Block
DATA STEP Data
Explanation : This DATA STEP block initializes and populates the 'heights' dataset directly from the data provided in the script via the `datalines` statement. It defines three variables: 'Family' (numeric), 'G' (gender, character), and 'Height' (numeric).
Copied!
data heights;
input Family G$ Height;
datalines;
1 F 67
1 F 66
1 F 64
1 M 71
1 M 72
2 F 63
2 F 63
2 F 67
2 M 69
2 M 68
2 M 70
3 F 63
3 M 64
4 F 67
4 F 66
4 M 67
4 M 67
4 M 69
;
1
DATA heights;
2
INPUT Family G$ Height;
3
DATALINES;
4
1 F 67
5
1 F 66
6
1 F 64
7
1 M 71
8
1 M 72
9
2 F 63
10
2 F 63
11
2 F 67
12
2 M 69
13
2 M 68
14
2 M 70
15
3 F 63
16
3 M 64
17
4 F 67
18
4 F 66
19
4 M 67
20
4 M 67
21
4 M 69
22
;
23
2 Code Block
DATA STEP Data
Explanation : This DATA STEP block creates a new dataset named 'input' by reading 'heights'. It transforms the categorical variable 'G' (gender) into a numerical indicator variable 'gf' (1 for Female, 0 for Male) and removes the original 'G' variable for subsequent analysis.
Copied!
data input;
set heights;
if g eq 'F' then gf = 1;
else gf = 0;
drop g;
run;
1
DATAINPUT;
2
SET heights;
3
IF g eq 'F'THEN gf = 1;
4
ELSE gf = 0;
5
drop g;
6
RUN;
7
3 Code Block
ODS Statement
Explanation : Activates the ODS (Output Delivery System) graphics system to allow for the generation of high-resolution graphs by SAS procedures.
Copied!
ods graphics on;
1
ods graphics on;
2
4 Code Block
PROC MCMC
Explanation : This MCMC (Monte Carlo Markov Chain) procedure fits a random effects model to the 'input' dataset. It generates an output dataset 'postout' containing the post-MCMC samples. Model parameters are initialized, and prior distributions are specified for the intercept (b0), gender coefficient (b1), residual variance (s2), and random effects variance (s2g). A random effect 'gamma' is defined for each 'family'. The model specifies that 'height' follows a normal distribution with a mean 'mu' (a function of fixed and random effects) and a variance 's2'. The number of iterations (nmc) and the random seed are fixed, and trace plots are requested.
random gamma ~ normal(0, var = s2g) subject=family monitor=(gamma);
8
mu = b0 + b1 * gf + gamma;
9
model height ~ normal(mu, var = s2);
10
RUN;
11
5 Code Block
ODS Statement
Explanation : Deactivates the ODS graphics system, thus stopping the generation of graphics.
Copied!
ods graphics off;
1
ods graphics off;
2
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: MCMCGS3, TITLE: Getting Started Example 3 for PROC MCMC, PRODUCT: STAT, SYSTEM: ALL, KEYS: random-effects model, PROCS: MCMC, DATA:, REF: PROC MCMC, GETTING STARTED EXAMPLE 3, MISC:
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.