BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Salah
Quartz | Level 8

Hello 

 

I have m failure observations X_1,X_2,...,X_m. The study ends at time (T) I may observe the mth failure before time T and I may not. If the mth failure is observed after time T then I have to know its value. However, I don't know how to write that part and I really appreciate any help.

AT the same time I need to know the failure value that took place just before T and its position, i.e.   the j value such that X_(j) < T < X_(j+1). For this I wrote the code below

 

call sortndx(idx, x, 1);

do idx=1 to m;

if (( X[idx] < T) & (X[idx+1] > T)) then j=idx;

end;

print  j;

 

Unfortunately, I keep on getting the following error message

 

Salah_0-1617137502658.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

The error message tells you that you are trying to access X[6] even though X only has 5 elements.

 

The problem occurs because the second part of your IF/THEN statement has the expression

X[idx+1] > T

and idx+1=6 when the loop index has the value idx=5.

 

I'm not sure what you are trying to accomplish with the loop, but if you want to find all elements of X that are less than T, you can use

k = loc(X<T);

if k is empty, then no failures occurred before T. If k is not empty, then X[k[ncol(k)]] is the value of the greatest time less than T.

View solution in original post

1 REPLY 1
Rick_SAS
SAS Super FREQ

The error message tells you that you are trying to access X[6] even though X only has 5 elements.

 

The problem occurs because the second part of your IF/THEN statement has the expression

X[idx+1] > T

and idx+1=6 when the loop index has the value idx=5.

 

I'm not sure what you are trying to accomplish with the loop, but if you want to find all elements of X that are less than T, you can use

k = loc(X<T);

if k is empty, then no failures occurred before T. If k is not empty, then X[k[ncol(k)]] is the value of the greatest time less than T.

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 1 reply
  • 526 views
  • 0 likes
  • 2 in conversation