The data is created directly within the script via a DATA step and a 'datalines' statement. It does not come from SASHELP or an external source.
1 Code Block
DATA STEP Data
Explanation : This block creates the SAS table 'rats'. It reads the variables 'trt' (treatment), 'm' (number of trials), and 'x' (number of successes) from embedded data (datalines). It generates indicator variables 'x1' and 'x2' for the control and treatment groups respectively. A litter identifier ('litter') is created using the observation number (_n_).
Copied!
data rats;
input trt $ m x @;
if (trt='c') then do;
x1 = 1;
x2 = 0;
end;
else do;
x1 = 0;
x2 = 1;
end;
litter = _n_;
datalines;
c 13 13 c 12 12 c 9 9 c 9 9 c 8 8 c 8 8 c 13 12 c 12 11
c 10 9 c 10 9 c 9 8 c 13 11 c 5 4 c 7 5 c 10 7 c 10 7
t 12 12 t 11 11 t 10 10 t 9 9 t 11 10 t 10 9 t 10 9 t 9 8
t 9 8 t 5 4 t 9 7 t 7 4 t 10 5 t 6 3 t 10 3 t 7 0
;
1
DATA rats;
2
INPUT trt $ m x @;
3
IF (trt='c') THENDO;
4
x1 = 1;
5
x2 = 0;
6
END;
7
ELSEDO;
8
x1 = 0;
9
x2 = 1;
10
END;
11
litter = _n_;
12
DATALINES;
13
c 1313 c 1212 c 99 c 99 c 88 c 88 c 1312 c 1211
14
c 109 c 109 c 98 c 1311 c 54 c 75 c 107 c 107
15
t 1212 t 1111 t 1010 t 99 t 1110 t 109 t 109 t 98
16
t 98 t 54 t 97 t 74 t 105 t 63 t 103 t 7 0
17
;
18
2 Code Block
PROC NLMIXED Data
Explanation : This block fits a nonlinear mixed model to the 'rats' table. It defines the initial parameters (parms), the linear predictor 'eta', and the probability 'p' via the probit function (probnorm). The model specifies a binomial distribution for the response 'x'. A random effect 'alpha' with a different variance per treatment group is included and grouped by 'litter'. An estimate of a ratio is calculated with 'estimate', and the predicted probabilities are saved in a new table 'p' with 'predict'.
Copied!
proc nlmixed data=rats;
parms t1=1 t2=1 s1=.05 s2=1;
eta = x1*t1 + x2*t2 + alpha;
p = probnorm(eta);
model x ~ binomial(m,p);
random alpha ~ normal(0,x1*s1*s1+x2*s2*s2) subject=litter;
estimate 'gamma2' t2/sqrt(1+s2*s2);
predict p out=p;
run;
1
PROC NLMIXEDDATA=rats;
2
parms t1=1 t2=1 s1=.05 s2=1;
3
eta = x1*t1 + x2*t2 + alpha;
4
p = probnorm(eta);
5
model x ~ binomial(m,p);
6
random alpha ~ normal(0,x1*s1*s1+x2*s2*s2) subject=litter;
7
estimate 'gamma2' t2/sqrt(1+s2*s2);
8
predict p out=p;
9
RUN;
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.
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.