The script initializes a dataset named 'surgery' using `datalines` to simulate clinical study results ('y' successes out of 'n' trials). It creates auxiliary variables 'treat2' and 'no', and transforms the 'treat' variable. Subsequently, two `NLMIXED` procedures are executed. The first adjusts a binomial logistic model with an uncorrelated random effect ('a') by study ('subject=study'). The second performs a more complex adjustment, incorporating two correlated random effects ('a' and 'b') and an interaction between 'b' and 'treat', specifying a number of quadrature points (`qpoints=50`) and generating a prediction dataset 'new2'.
Data Analysis
Type : INTERNAL_CREATION
Data is created directly within the script via a DATA step and `datalines`, forming the 'surgery' dataset. Although a string resembling a JSON file path is present in the `input` statement, it is not interpreted as an external data source for this specific DATA step, as the data is provided directly after `cards;`.
1 Code Block
DATA STEP Data
Explanation : This DATA STEP block creates the 'surgery' dataset using `datalines`. It reads the variables 'study', 'treat', 'y' (number of successes), and 'n' (total number of trials). The string ' @code_sas_json/hsdua2304@gmail.com_SAS_Assignment_1.json' is present in the `input` statement but is not standard syntax for reading external data in this context and is interpreted literally. The block then calculates 'no' (number of failures) and transforms the 'treat' variable from 1 to 0.5 and from 0 to -0.5, thus preparing the data for subsequent analyses.
INPUT study treat y n @code_sas_json/hsdua2304@gmail.com_SAS_Assignment_1.json ; * y successes out of n trials;
3
treat2 = treat;
4
no=n-y;
5
IF treat = 1THEN treat = .5; ELSE treat = -.5;
6
CARDS;
7
117151 0 1113
8
218192 0 816
9
315343 0 439
10
417364 0 431
11
513125 0 0 12
12
61476 0 44
13
714177 0 1324
14
811168 0 1316
15
913149 0 722
16
10123810 0 1232
17
11161211 0 88
18
1212712 0 79
19
13192113 0 724
20
14172114 0 525
21
15132515 0 1132
22
16141116 0 610
23
17121017 0 810
24
18113118 0 427
25
19142819 0 1531
26
20174320 0 1643
27
21164021 0 1321
28
22141822 0 539
29
231146823 0 1374
30
24162124 0 821
31
251 0 625 0 66
32
26111026 0 515
33
27151727 0 515
34
281 0 1028 0 1214
35
291 0 2229 0 824
36
30121830 0 1021
37
31111531 0 713
38
32182432 0 1527
39
33161233 0 79
40
341 0 2034 0 523
41
35141735 0 216
42
361104036 0 1220
43
37131637 0 216
44
38143438 0 519
45
39173839 0 1537
46
401 0 3440 0 3434
47
411 0 941 0 0 16
48
;
2 Code Block
PROC NLMIXED
Explanation : This first `PROC NLMIXED` block fits a nonlinear mixed model. It models the probability 'pi' of 'y' successes out of 'n' trials using a logistic function with a random effect 'a' for each 'study'. The random effect 'a' follows a normal distribution with mean 'alpha' and variance 'sig*sig', with no interaction specified with other variables.
Copied!
/* (11.7) */
proc nlmixed; * random effects, no interaction;
pi = exp(a + beta*treat)/(1+exp(a + beta*treat)); * logistic formula for prob;
model y ~ binomial(n, pi);
random a ~ normal(alpha, sig*sig) subject=study;
1
/* (11.7) */
2
PROC NLMIXED; * random effects, no interaction;
3
pi = exp(a + beta*treat)/(1+exp(a + beta*treat)); * logistic formula for prob;
4
model y ~ binomial(n, pi);
5
random a ~ normal(alpha, sig*sig) subject=study;
3 Code Block
PROC NLMIXED Data
Explanation : This second `PROC NLMIXED` block fits a more complex model with correlated random effects. It includes two random effects, 'a' and 'b', which are assumed to follow a correlated multivariate normal distribution. The probability 'pi' incorporates an interaction of 'b' with 'treat'. The `qpoints=50` option is used for quadrature integral calculation. Furthermore, the `predict` clause is used to predict the values of 'beta + b' and save them to a new dataset named 'new2'.
Copied!
/* (11.8) */
proc nlmixed qpoints=50; * correlated random effects, interaction;
pi = exp(alpha + a + beta*treat + b*treat)/(1+exp(alpha + a + beta*treat + b*treat));
model y ~ binomial(n, pi);
random a b ~ normal([0,0], [sig_a*sig_a, rho ,sig_b*sig_b]) subject=study;
predict beta + b out=new2;
run;
1
/* (11.8) */
2
PROC NLMIXED qpoints=50; * correlated random effects, interaction;
3
pi = exp(alpha + a + beta*treat + b*treat)/(1+exp(alpha + a + beta*treat + b*treat));
4
model y ~ binomial(n, pi);
5
random a b ~ normal([0,0], [sig_a*sig_a, rho ,sig_b*sig_b]) subject=study;
6
predict beta + b out=new2;
7
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.