Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 11-03-2020 07:05 AM
(456 views)

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:

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;

72

73 proc iml;

NOTE: IML Ready

74 /* If x is univariate, you can construct a matrix where

75 each column contains a jackknife sample.

76 Use for univariate column vector x when n < 20000 */

77 start JackSampMat(x);

78 n = nrow(x);

79 B = j(n-1, n,0);

80 do i = 1 to n;

81 B[,i] = remove(x, i)`;

81 ! /* transpose to column vevtor */

82 end;

83 return B;

84 finish;

NOTE: Module JACKSAMPMAT defined.

85

86 /* Input: matrix where each column of X is a bootstrap sample.

87 Return a row vector of statistics, one for each column. */

88 start EvalStatMat(x);

89 return std(x);

89 ! /* <== Example: return std dev of each sample */

90 finish;

NOTE: Module EVALSTATMAT defined.

91

92 x = {58,67,74,74,80,89,95,97,98,107};

92 ! /* Weight gain (g) for 10 rats */

93

94 /* optional: visualize the matrix of jackknife samples */

95 *M = JackSampMat(x);

96 *print M[c=("S1":"S10") r=("1":"9")];

97

98 /* Jackknife method for univariate data */

99 /* 1. compute observed statistic */

100 T = EvalStatMat(x);

101 /* 2. compute same statistic on each jackknife sample */

102 T_LOO = EvalStatMat( JackSampMat(x) );

102 ! /* LOO = "Leave One Out" */

103 /* 3. compute mean of the LOO statistics */

104 T_Avg = mean( T_LOO` );

104 ! /* transpose T_LOO */

105 /* 4 & 5. compute jackknife estimates of bias and standard 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)

*LIT1005 1 row 1 col (numeric)

1

statement : ASSIGN at line 106 column 1

107 stdErrJack = sqrt( (n-1)/n * ssq(T_LOO - T_Avg) );

ERROR: (execution) Matrix has not been set to a value.

operation : - at line 107 column 22

operands : n, *LIT1006

n 0 row 0 col (type ?, size 0)

*LIT1006 1 row 1 col (numeric)

1

statement : ASSIGN at line 107 column 1

108 result = T || T_Avg || biasJack || stdErrJack;

109 print result[c={"Estimate" "Mean Jackknife Estimate" "Bias" "Std Error"}];

110

111 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;

123

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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"}];

5 REPLIES 5

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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"}];

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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)

It is telling you that N has 0 rows and 0 columns, and so you can't do any math with such a matrix. N is not defined. It doesn't matter that earlier in the program, you defined N within a specific module named JackSampMat, that N is only available within JackSampMat.

But don't bother writing your own Jackknife code. SAS's @Rick_SAS has done this for you at https://blogs.sas.com/content/iml/2017/06/21/jackknife-estimate-standard-error-sas.html

PS: @am557 in the future, please post code by clicking on the "running man" icon, and please post your log by clicking on the </> icon (as I did), this preserves the formatting of the code or log, and makes it more readable. Thanks!

--

Paige Miller

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

You didn't define variable N at global scope .

Better post it at IML forum . @Rick_SAS is there.

Better post it at IML forum . @Rick_SAS is there.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

**If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. **

Multiple Linear Regression in SAS

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.