While running the below code I am getting an error saying: ERROR: (execution) Matrix has not been set to a value.
Please find below the code and the log.
proc iml;
/* If x is univariate, you can construct a matrix where
each column contains a jackknife sample.
Use for univariate column vector x when n < 20000 */
start JackSampMat(x);
n = nrow(x);
B = j(n-1, n,0);
do i = 1 to n;
B[,i] = remove(x, i)`; /* transpose to column vevtor */
end;
return B;
finish;
/* Input: matrix where each column of X is a bootstrap sample.
Return a row vector of statistics, one for each column. */
start EvalStatMat(x);
return std(x); /* <== Example: return std dev of each sample */
finish;
x = {58,67,74,74,80,89,95,97,98,107}; /* Weight gain (g) for 10 rats */
/* optional: visualize the matrix of jackknife samples */
*M = JackSampMat(x);
*print M[c=("S1":"S10") r=("1":"9")];
/* Jackknife method for univariate data */
/* 1. compute observed statistic */
T = EvalStatMat(x);
/* 2. compute same statistic on each jackknife sample */
T_LOO = EvalStatMat( JackSampMat(x) ); /* LOO = "Leave One Out" */
/* 3. compute mean of the LOO statistics */
T_Avg = mean( T_LOO` ); /* transpose T_LOO */
/* 4 & 5. compute jackknife estimates of bias and standard error */
biasJack = (n-1)*(T_Avg - T);
stdErrJack = sqrt( (n-1)/n * ssq(T_LOO - T_Avg) );
result = T || T_Avg || biasJack || stdErrJack;
print result[c={"Estimate" "Mean Jackknife Estimate" "Bias" "Std Error"}];
Log says:
N is only defined locally, that is within the JackSampMat module. To reference it outside the module you will need to define it globally by adding the GLOBAL clause to the module definition.
proc iml;
/* If x is univariate, you can construct a matrix where
each column contains a jackknife sample.
Use for univariate column vector x when n < 20000 */
start JackSampMat(x) global(n);
n = nrow(x);
B = j(n-1, n,0);
do i = 1 to n;
B[,i] = remove(x, i)`; /* transpose to column vevtor */
end;
return B;
finish;
/* Input: matrix where each column of X is a bootstrap sample.
Return a row vector of statistics, one for each column. */
start EvalStatMat(x);
return std(x); /* <== Example: return std dev of each sample */
finish;
x = {58,67,74,74,80,89,95,97,98,107}; /* Weight gain (g) for 10 rats */
/* optional: visualize the matrix of jackknife samples */
*M = JackSampMat(x);
*print M[c=("S1":"S10") r=("1":"9")];
/* Jackknife method for univariate data */
/* 1. compute observed statistic */
T = EvalStatMat(x);
/* 2. compute same statistic on each jackknife sample */
T_LOO = EvalStatMat( JackSampMat(x) ); /* LOO = "Leave One Out" */
/* 3. compute mean of the LOO statistics */
T_Avg = mean( T_LOO` ); /* transpose T_LOO */
/* 4 & 5. compute jackknife estimates of bias and standard error */
biasJack = (n-1)*(T_Avg - T);
stdErrJack = sqrt( (n-1)/n * ssq(T_LOO - T_Avg) );
result = T || T_Avg || biasJack || stdErrJack;
print result[c={"Estimate" "Mean Jackknife Estimate" "Bias" "Std Error"}];
N is only defined locally, that is within the JackSampMat module. To reference it outside the module you will need to define it globally by adding the GLOBAL clause to the module definition.
proc iml;
/* If x is univariate, you can construct a matrix where
each column contains a jackknife sample.
Use for univariate column vector x when n < 20000 */
start JackSampMat(x) global(n);
n = nrow(x);
B = j(n-1, n,0);
do i = 1 to n;
B[,i] = remove(x, i)`; /* transpose to column vevtor */
end;
return B;
finish;
/* Input: matrix where each column of X is a bootstrap sample.
Return a row vector of statistics, one for each column. */
start EvalStatMat(x);
return std(x); /* <== Example: return std dev of each sample */
finish;
x = {58,67,74,74,80,89,95,97,98,107}; /* Weight gain (g) for 10 rats */
/* optional: visualize the matrix of jackknife samples */
*M = JackSampMat(x);
*print M[c=("S1":"S10") r=("1":"9")];
/* Jackknife method for univariate data */
/* 1. compute observed statistic */
T = EvalStatMat(x);
/* 2. compute same statistic on each jackknife sample */
T_LOO = EvalStatMat( JackSampMat(x) ); /* LOO = "Leave One Out" */
/* 3. compute mean of the LOO statistics */
T_Avg = mean( T_LOO` ); /* transpose T_LOO */
/* 4 & 5. compute jackknife estimates of bias and standard error */
biasJack = (n-1)*(T_Avg - T);
stdErrJack = sqrt( (n-1)/n * ssq(T_LOO - T_Avg) );
result = T || T_Avg || biasJack || stdErrJack;
print result[c={"Estimate" "Mean Jackknife Estimate" "Bias" "Std Error"}];
106 biasJack = (n-1)*(T_Avg - T); ERROR: (execution) Matrix has not been set to a value. operation : - at line 106 column 14 operands : n, *LIT1005 n 0 row 0 col (type ?, size 0)
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.