BookmarkSubscribeRSS Feed
Mike7
Calcite | Level 5

Dear All,

 

I was trying to run this and I got this for the 3 matrices created "(Execution) Matrices has not been set a value";

 

proc iml;
*part a;
n = 10;
x1 = j(10,1,1);
x2 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
x = x1 || x2;
M = 1000;
B10 = j(M,1,0);
T10 = j(M,1,0);
title "Answer to part a";
print x1 x2 x M B10 T10;

*part b;
u = j(n,1,0);
Btot = {1, 2};
Var = {2};

*part c;
do i = 1 to M;
call randgen(u,"normal",0,Var);
y = (x*BTot) + u;

b = inv((x`) * x) * (x`) * y;
e = y - (x*b);
b2 = b[2,1];
B10[i,] = b2;

B2 = Btot[2,1];
se2 = ((e`) * e) * (1/(n - 2));
varb2 = s2 * b2;
seb2 = sqrt(varb2);
t2 = (b2 - B2) * (1/seb2);
T10[i,] = t2;
end;

*part d;
n = 100;
x_1 = j(100,1,1);
x_2 = repeat({1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 10);
x = x_1 || x_2;
M = 1000;
B100 = j(M,1,0);
T100 = j(M,1,0);
u = j(n,1,0);
Btot = {1, 2};
S = {2};

do i = 1 to M;
call randgen(u,"normal",0,S);
y = (x*B_pop) + u;

b = inv((x`) * x) * (x`) * y;
e = y - (x*b);
b2 = b[2,1];
B100[i,] = b2;

B2 = Btot[2,1];
se2 = ((e`) * e) * (1/(n - 2));
varb2 = se2 * b2;
seb2 = sqrt(varb2);
t2 = (b2 - B2) * (1/seb2);
T100[i,] = t2;
end;

*part e;
n = 1000;
x1 = j(1000,1,1);
x2 = repeat({1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 100);
x = x1 || x2;
M = 1000;
B1000 = j(M,1,0);
T1000 = j(M,1,0);
u = j(n,1,0);
Btot = {1, 2};
Var = {2};

do i = 1 to M;
call randgen(u,"normal",0,S);
y = (x*Btot) + u;

b = inv((x`) * x) * (x`) * y;
e = y - (x*b);
b2 = b[2,1];
B1000[i,] = b2;

B2 = Btot[2,1];
se2 = ((e`) * e) * (1/(n - 2));
varb2 = se2 * b2;
seb2 = sqrt(varb2);
t2 = (b2 - B2) * (1/seb2);
T1000[i,] = t_2;
end;

9 REPLIES 9
Reeza
Super User

Can you narrow it down to which part of your code is generating the error? And including the log is helpful as well. 

 

 


@Mike7 wrote:

Dear All,

 

I was trying to run this and I got this for the 3 matrices created "(Execution) Matrices has not been set a value";

 

proc iml;
*part a;
n = 10;
x1 = j(10,1,1);
x2 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
x = x1 || x2;
M = 1000;
B10 = j(M,1,0);
T10 = j(M,1,0);
title "Answer to part a";
print x1 x2 x M B10 T10;

*part b;
u = j(n,1,0);
Btot = {1, 2};
Var = {2};

*part c;
do i = 1 to M;
call randgen(u,"normal",0,Var);
y = (x*BTot) + u;

b = inv((x`) * x) * (x`) * y;
e = y - (x*b);
b2 = b[2,1];
B10[i,] = b2;

B2 = Btot[2,1];
se2 = ((e`) * e) * (1/(n - 2));
varb2 = s2 * b2;
seb2 = sqrt(varb2);
t2 = (b2 - B2) * (1/seb2);
T10[i,] = t2;
end;

*part d;
n = 100;
x_1 = j(100,1,1);
x_2 = repeat({1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 10);
x = x_1 || x_2;
M = 1000;
B100 = j(M,1,0);
T100 = j(M,1,0);
u = j(n,1,0);
Btot = {1, 2};
S = {2};

do i = 1 to M;
call randgen(u,"normal",0,S);
y = (x*B_pop) + u;

b = inv((x`) * x) * (x`) * y;
e = y - (x*b);
b2 = b[2,1];
B100[i,] = b2;

B2 = Btot[2,1];
se2 = ((e`) * e) * (1/(n - 2));
varb2 = se2 * b2;
seb2 = sqrt(varb2);
t2 = (b2 - B2) * (1/seb2);
T100[i,] = t2;
end;

*part e;
n = 1000;
x1 = j(1000,1,1);
x2 = repeat({1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 100);
x = x1 || x2;
M = 1000;
B1000 = j(M,1,0);
T1000 = j(M,1,0);
u = j(n,1,0);
Btot = {1, 2};
Var = {2};

do i = 1 to M;
call randgen(u,"normal",0,S);
y = (x*Btot) + u;

b = inv((x`) * x) * (x`) * y;
e = y - (x*b);
b2 = b[2,1];
B1000[i,] = b2;

B2 = Btot[2,1];
se2 = ((e`) * e) * (1/(n - 2));
varb2 = se2 * b2;
seb2 = sqrt(varb2);
t2 = (b2 - B2) * (1/seb2);
T1000[i,] = t_2;
end;




Mike7
Calcite | Level 5

its generating errors in the three parts, when trying to create T10, T100, and T1000

 

Its telling me that the matric has not been set a value; however I tried setting a value in the beginning but did not work

Reeza
Super User

That's not what it's saying. Read the error thoroughly and fix what it indicates is the error. 

FYI it's a typo.

Mike7
Calcite | Level 5

I fixed the Typo, but still getting errors for T10 T100 T1000

Reeza
Super User

Out of curiosity how am I supposed to have any idea of either what the error or your code looks like now? 

 

Post your modified code AND log with errors. 

Mike7
Calcite | Level 5

i fixed the typo but i am having problems with another error

(execution) Invalid subscript or subscript out of range

Ksharp
Super User

 

83         varb2 = s2 * b2;
 84         seb2 = sqrt(varb2);
 85         t2 = (b2 - B2) * (1/seb2);
 86         T10[i,] = t2;
 87         end;
 ERROR: (execution) Matrix has not been set to a value.
 
  operation : * at line 83 column 12
  operands  : s2, b2
 
 s2      0 row       0 col     (type ?, size 0)

According to LOG, it said you did not define s2 before . I think s2 should be se2 ?

 

 

Ksharp
Super User

Also you do not define B_pop  ,are supposed to be Btot

t_2 is supposed to be t2?

 

 


proc iml;
*part a;
n = 10;
x1 = j(10,1,1);
x2 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
x = x1 || x2;
M = 1000;
B10 = j(M,1,0);
T10 = j(M,1,0);
title "Answer to part a";
print x1 x2 x M B10 T10;
*part b;
u = j(n,1,0);
Btot = {1, 2};
Var = {2};
*part c;
do i = 1 to M;
call randgen(u,"normal",0,Var);
y = (x*BTot) + u;

b = inv((x`) * x) * (x`) * y;
e = y - (x*b);
b2 = b[2,1];
B10[i,] = b2;
B2 = Btot[2,1];
se2 = ((e`) * e) * (1/(n - 2));
varb2 = se2 * b2;
seb2 = sqrt(varb2);
t2 = (b2 - B2) * (1/seb2);
T10[i,] = t2;
end;
*part d;
n = 100;
x_1 = j(100,1,1);
x_2 = repeat({1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 10);
x = x_1 || x_2;
M = 1000;
B100 = j(M,1,0);
T100 = j(M,1,0);
u = j(n,1,0);
Btot = {1, 2};
S = {2};
do i = 1 to M;
call randgen(u,"normal",0,S);
y = (x*Btot) + u;

b = inv((x`) * x) * (x`) * y;
e = y - (x*b);
b2 = b[2,1];
B100[i,] = b2;
B2 = Btot[2,1];
se2 = ((e`) * e) * (1/(n - 2));
varb2 = se2 * b2;
seb2 = sqrt(varb2);
t2 = (b2 - B2) * (1/seb2);
T100[i,] = t2;
end;
*part e;
n = 1000;
x1 = j(1000,1,1);
x2 = repeat({1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 100);
x = x1 || x2;
M = 1000;
B1000 = j(M,1,0);
T1000 = j(M,1,0);
u = j(n,1,0);
Btot = {1, 2};
Var = {2};
do i = 1 to M;
call randgen(u,"normal",0,S);
y = (x*Btot) + u;

b = inv((x`) * x) * (x`) * y;
e = y - (x*b);
b2 = b[2,1];
B1000[i,] = b2;
B2 = Btot[2,1];
se2 = ((e`) * e) * (1/(n - 2));
varb2 = se2 * b2;
seb2 = sqrt(varb2);
t2 = (b2 - B2) * (1/seb2);
T1000[i,] = t2;
end;
quit;

 

 

 

Reeza
Super User

@Ksharp and here I was trying to let 'Mike' do his own homework 😉

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 9 replies
  • 1823 views
  • 2 likes
  • 3 in conversation