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

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

Posted 11-21-2012 07:09 AM
(1294 views)

i need help in certain program i am writing in a do until loop, loop doesn't end unless condition is broken from the first time, if the condition continues to hold the program does not end, Could u pls help me ?

proc iml;

n=3;

p=2;

m=10;

k=1;

nruns=100;

yvec=0;

sigma=1;

T=n*(k+m);

x1={1,4,3};

x2={2,3,5};

xp={1 2,4 3,3 5};

l=j(n,1,1);

x=l||x1||x2;

x11=repeat(x1,(m+k));

x22=repeat(x2,(m+k));

i=j(T,1,1);

xx=i||x11||x22;

z=T({ [30] 0 [3] 1});

z0=z#i;

zx1=z#x11;

zx2=z#x22;

xxf=i||z0||x11||zx1||x22||zx2;

beta0=1;

beta1=2;

beta2=3;

alpha=0.005;

alpha1=1-(1-alpha)**2/3;

df1=p+1;

df2=T-2*(p+1);

fdis=finv((1-alpha),df1,df2);

do i=1 to m;

epslon1=sigma* normal(repeat(-1,n));

y=beta0+(beta1)*x1+(beta2)*x2+epslon1;

yvec=yvec//y;

xty=T(x)*y;

beta=inv(T(x)*x)*xty;

yhat=x*beta;

msej=ssq(y-yhat)/(n-p);

msec=msec//msej;

end;

yvec1=yvec;

mse=sum(msec)/m;

shiftvec={0,0.05,1,1.5,2,2.5,3,3.5,4,4.5,5};

nshf=nrow(shiftvec);

arlvec=0;

do k=1 to nshf;

shift=shiftvec[k,];

c=0;

do i=1 to nruns;

arl=0;

ftest=0;

do until (ftest>fdis);

epslon=sigma* normal(repeat(-1,n));

y=beta0+(beta1+shift)*x1+(beta2)*x2+epslon;

yvec1=yvec1//y;

bhatr=inv(T(xx)*xx)*T(xx)*yvec1[2:34,];

yhatr=xx*bhatr;

err=yvec1[2:34,]-yhatr;

sser=T(err)*err;

bhatf=inv(T(xxf)*xxf)*T(xxf)*yvec1[2:34,];

yhatf=xxf*bhatf;

erf=yvec1[2:34,]-yhatf;

ssef=T(erf)*erf;

msef=T(erf)*erf/(T-2*(p+1));

ftest=(sser-ssef)/((p+1)*msef);

arl=arl+1;

end;

c=c+arl;

end;

avrl=c/nruns;

avrlvec=avrlvec//avrl;

end;

print sser ssef c arl avrl arlvec ftest fdis msef shift;

quit;

10 REPLIES 10

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

All the computations inside the DO-UNTIL loop are the same after the second iteration. Therefore the loop will never end.

You write

yvec1=yvec1//y;

which makes it look like you are changing yvec1. However, the rest of the loop only uses the first 34 rows, which are constant.

While you are debugging the program, use

DO UNTIL(ftest>fdis | arl>5);

in order to avoid the infinite loop.

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

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

1) First, get the code working for a particular choice of arl. When it is all debugged and working, you can add a loop for different shifts.

2) Yes, y is different for each loop, but you never access y inside the DO-UNTIL loop. You append each y to the END of yvec1, but you only use the BEGINNING of yvec1.

3) I don't know what you mean by "any other way to solve it without specifying the arl" because I don't understand what the program is doing. Perhaps you should annotate the code with comments and explanations. I see a simulation of random errors for a linear regression models with various choices for beta1, but I don't understand what you are trying to accomplish, nor do I understand why you expect the DO-UNTIL loop to end. Why should the value of the F test ever exceed the critical value that you set?

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

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

I am a little confused by yvec versus yvec1, but I think this is what you want to do. Maybe you'll be able to see the main idea.

1) Outside the first DO loop, allocate yvec to have 33 elements:

yvec = j(33,1);

2) Inside the first DO loop, assign the first 30 elements to the vector y from the no-shift model :

yvec[1:30] = y;

I might not be understanding something (or you have a bug in your program) because y, x1, x2, and epslon1 should have 30 elements, shouldn't they?

3) Inside the DO-UNTIL loop, generate a three-element vector, which I'll call yy, from the shifted regression model. Assign yy to the last three elements of yvec:

yvec[31:33] = yy;

I hope that will get you started. Start with something simple, debug teh simple code, and then gradually add complexities.

Hope this helps.

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

Sorry to bother u again, and thanx a lot for ur help. I understood the above problem and I was able to fix it, now I did a little adjustment on the codes and the loop doesn't end, here are the new codes:

proc iml;

n=3;

p=2;

m=10;

k=1;

nruns=10000;

yvec=0;

avrlvec=0;

sigma=1;

T=n*(k+m);

x1={1,4,3};

x2={2,3,5};

xp={1 2,4 3,3 5};

l=j(n,1,1);

x=l||x1||x2;

x11=repeat(x1,(m+k));

x22=repeat(x2,(m+k));

i=j(T,1,1);

xx=i||x11||x22;

z=T({ [30] 0 [3] 1});

z0=z#i;

zx1=z#x11;

zx2=z#x22;

xxf=i||z0||x11||zx1||x22||zx2;

beta0=1;

beta1=2;

beta2=3;

alpha=0.05;

alpha1=1-(1-alpha)**2/3;

df1=p+1;

df2=T-2*(p+1);

fdis=finv((1-alpha),df1,df2);

shiftvec={0,0.5,1,1.5,2,2.5,3,3.5,4,4.5,5};

nshf=nrow(shiftvec);

do k=1 to nshf;

shift=shiftvec[k,];

c=0;

do i=1 to nruns;

yvec=0;

do i=1 to m;

epslon1=sigma* normal(repeat(-1,n));

y=beta0+(beta1)*x1+(beta2)*x2+epslon1;

yvec=yvec//y;

xty=T(x)*y;

beta=inv(T(x)*x)*xty;

yhat=x*beta;

msej=ssq(y-yhat)/(n-p);

msec=msec//msej;

end;

yvec1=yvec;

mse=sum(msec)/m;

arl=0;

ftest=0;

do until (ftest>fdis);

yvec1=yvec;

epslon=sigma* normal(repeat(-1,n));

y1=beta0+(beta1+shift)*x1+(beta2)*x2+epslon;

yvec1=yvec1//y1;

bhatr=inv(T(xx)*xx)*T(xx)*yvec1[2:34,];

yhatr=xx*bhatr;

err=yvec1[2:34,]-yhatr;

sser=T(err)*err;

bhatf=inv(T(xxf)*xxf)*T(xxf)*yvec1[2:34,];

yhatf=xxf*bhatf;

erf=yvec1[2:34,]-yhatf;

ssef=T(erf)*erf;

msef=T(erf)*erf/(T-2*(p+1));

ftest=(sser-ssef)/((p+1)*msef);

arl=arl+1;

numb=nrow (yvec1);

end;

c=c+arl;

end;

avrl=c/nruns;

avrlvec=avrlvec//avrl;

end;

print yvec1 avrlvec ftest fdis msef numb shift ;

quit;

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

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

+1 for Art!

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

Thanx a lot, I am sorry to keep bothering you, but you really save me with your answers

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

Yes, I figured it yesterday, thanx a lot for your reply.

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.