SAS:引用了错误变量但未给定值

SAS: Error Variable was referenced but not given value

data iris;
input sepal_length sepal_width petal_length petal_width class $ @@;
Datalines;
5.1 3.5 1.4 0.2 Iris-setosa
4.9 3.0 1.4 0.2 Iris-setosa
4.7 3.2 1.3 0.2 Iris-setosa
4.6 3.1 1.5 0.2 Iris-setosa
5.0 3.6 1.4 0.2 Iris-setosa
5.4 3.9 1.7 0.4 Iris-setosa
4.6 3.4 1.4 0.3 Iris-setosa
5.0 3.4 1.5 0.2 Iris-setosa
4.4 2.9 1.4 0.2 Iris-setosa
4.9 3.1 1.5 0.1 Iris-setosa
5.4 3.7 1.5 0.2 Iris-setosa
4.8 3.4 1.6 0.2 Iris-setosa
4.8 3.0 1.4 0.1 Iris-setosa
4.3 3.0 1.1 0.1 Iris-setosa
5.8 4.0 1.2 0.2 Iris-setosa
5.7 4.4 1.5 0.4 Iris-setosa
5.4 3.9 1.3 0.4 Iris-setosa
5.1 3.5 1.4 0.3 Iris-setosa
5.7 3.8 1.7 0.3 Iris-setosa
5.1 3.8 1.5 0.3 Iris-setosa
5.4 3.4 1.7 0.2 Iris-setosa
5.1 3.7 1.5 0.4 Iris-setosa
4.6 3.6 1.0 0.2 Iris-setosa
5.1 3.3 1.7 0.5 Iris-setosa
4.8 3.4 1.9 0.2 Iris-setosa
5.0 3.0 1.6 0.2 Iris-setosa
5.0 3.4 1.6 0.4 Iris-setosa
5.2 3.5 1.5 0.2 Iris-setosa
5.2 3.4 1.4 0.2 Iris-setosa
4.7 3.2 1.6 0.2 Iris-setosa
4.8 3.1 1.6 0.2 Iris-setosa
5.4 3.4 1.5 0.4 Iris-setosa
5.2 4.1 1.5 0.1 Iris-setosa
5.5 4.2 1.4 0.2 Iris-setosa
4.9 3.1 1.5 0.1 Iris-setosa
5.0 3.2 1.2 0.2 Iris-setosa
5.5 3.5 1.3 0.2 Iris-setosa
4.9 3.1 1.5 0.1 Iris-setosa
4.4 3.0 1.3 0.2 Iris-setosa
5.1 3.4 1.5 0.2 Iris-setosa
5.0 3.5 1.3 0.3 Iris-setosa
4.5 2.3 1.3 0.3 Iris-setosa
4.4 3.2 1.3 0.2 Iris-setosa
5.0 3.5 1.6 0.6 Iris-setosa
5.1 3.8 1.9 0.4 Iris-setosa
4.8 3.0 1.4 0.3 Iris-setosa
5.1 3.8 1.6 0.2 Iris-setosa
4.6 3.2 1.4 0.2 Iris-setosa
5.3 3.7 1.5 0.2 Iris-setosa
5.0 3.3 1.4 0.2 Iris-setosa
7.0 3.2 4.7 1.4 Iris-versicolor
6.4 3.2 4.5 1.5 Iris-versicolor
6.9 3.1 4.9 1.5 Iris-versicolor
5.5 2.3 4.0 1.3 Iris-versicolor
6.5 2.8 4.6 1.5 Iris-versicolor
5.7 2.8 4.5 1.3 Iris-versicolor
6.3 3.3 4.7 1.6 Iris-versicolor
4.9 2.4 3.3 1.0 Iris-versicolor
6.6 2.9 4.6 1.3 Iris-versicolor
5.2 2.7 3.9 1.4 Iris-versicolor
5.0 2.0 3.5 1.0 Iris-versicolor
5.9 3.0 4.2 1.5 Iris-versicolor
6.0 2.2 4.0 1.0 Iris-versicolor
6.1 2.9 4.7 1.4 Iris-versicolor
5.6 2.9 3.6 1.3 Iris-versicolor
6.7 3.1 4.4 1.4 Iris-versicolor
5.6 3.0 4.5 1.5 Iris-versicolor
5.8 2.7 4.1 1.0 Iris-versicolor
6.2 2.2 4.5 1.5 Iris-versicolor
5.6 2.5 3.9 1.1 Iris-versicolor
5.9 3.2 4.8 1.8 Iris-versicolor
6.1 2.8 4.0 1.3 Iris-versicolor
6.3 2.5 4.9 1.5 Iris-versicolor
6.1 2.8 4.7 1.2 Iris-versicolor
6.4 2.9 4.3 1.3 Iris-versicolor
6.6 3.0 4.4 1.4 Iris-versicolor
6.8 2.8 4.8 1.4 Iris-versicolor
6.7 3.0 5.0 1.7 Iris-versicolor
6.0 2.9 4.5 1.5 Iris-versicolor
5.7 2.6 3.5 1.0 Iris-versicolor
5.5 2.4 3.8 1.1 Iris-versicolor
5.5 2.4 3.7 1.0 Iris-versicolor
5.8 2.7 3.9 1.2 Iris-versicolor
6.0 2.7 5.1 1.6 Iris-versicolor
5.4 3.0 4.5 1.5 Iris-versicolor
;
run;



/* Prior predictive checks */
PROC MCMC DATA = iris;
NMC = 5000; /* Size of the sample */
NBI = 0; /* No need to generate burn-in samples, because the draws are taken
directly from the prior */

ARRAY mu[3];
ARRAY sigma[3,3];
PARMS beta1 beta2 beta3 beta4;
PARMS mu;
PARMS sigma;

/* Hyperprior constants */
ARRAY mu0[3] (0 0 0);
ARRAY sigma0[3,3] (625, 200, 200, 200, 625, 200, 200, 200, 625);
ARRAY S[3,3] (500, 50, 50, 50, 500, 50, 50, 50, 500);
/* Prior distributions */
PRIOR beta: ~ NORM(0, var = 10000); /* Note that since the prior distributions for
beta1,beta2,beta3 and beta4 are independent, they can be programmed without a multivariate
distribution. */
PRIOR sigma ~ IWISH(5, S);
PRIOR mu ~ MVN(mu0, sigma0);
/* Constant likelihood function */
MODEL GENERAL(0);
RUN;



PROC MCMC DATA = iris;
NMC = 5000; NBI =0;thin=10;
INIT = RANDOM; /* Random initial values allow Gelman-Rubin diagnostics */

ARRAY mu[3];
ARRAY sigma[3,3];
PARMS beta1 beta2 beta3 beta4 mu sigma ; /* Since this model uses conjugate sampling, the
parameters can all be included in the same PARMS statement without being proposed
together. */
/* Hyperprior constants */
ARRAY mu0[3] (0 0 0);
ARRAY sigma0[3,3] (625, 200, 200, 200, 625, 200, 200, 200, 625);
ARRAY S[3,3] (500, 50, 50, 50, 500, 50, 50, 50, 500);
/* Prior distributions */
PRIOR beta :~ NORM(0, VAR = 10000);
PRIOR sigma ~ IWISH(5, S);
PRIOR mu ~ MVN(mu0, sigma0);
/* Data */
ARRAY class[3] setosa versicolor virginica;
ARRAY sepal_length[3] sepal_length_setosa sepal_length_versicolor sepal_length_virginica;
ARRAY sepal_width[3] sepal_width_setosa sepal_width_versicolor sepal_width_virginica;
ARRAY petal_length[3] petal_length_setosa petal_length_versicolor petal_length_virginica;
ARRAY petal_width[3] petal_width_setosa petal_width_versicolor petal_width_virginica;
ARRAY p[3]; /* Vector of probabilities */
ARRAY exp_eta[4]; /* Vector of linear predictor */
ARRAY alpha[3]; /* Random effects */
/* Sampling model */
RANDOM alpha ~ MVN(mu, sigma) SUBJECT = class MONITOR = (alpha);
/* Calculate exponentiated linear predictor */
DO j = 1 TO 4;
 exp_eta[j] = exp(alpha[j] + beta1 * sepal_length[j] + beta2 * sepal_width[j] + beta3 * petal_length[j] + beta4 * petal_width[j]);
END;
/* Calculate the denominator by summing over exp_eta. */
denom = exp_eta[1] + exp_eta[2] + exp_eta[3] + exp_eta[4];
/* Convert to probabilities */
DO j = 1 TO 4;
 p[j] = exp_eta[j]/denom;
END;
model class ~ MULTINOM(p);
RUN;

那是我的代码,但我一直收到错误消息:

ERROR: The variable RANDOM was referenced but not given a value.
ERROR: The variable sepal_length was referenced but not given a value.
ERROR: The variable sepal_width was referenced but not given a value.
ERROR: The variable petal_length was referenced but not given a value.
ERROR: The variable petal_width was referenced but not given a value.

我该如何解决?

您似乎指的是同一过程中同名的数组和变量。我不熟悉 proc mcmc,但如果您尝试在导致类似错误的数据步骤中执行此操作。

尝试重命名数组,看看问题是否仍然存在。