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

I'm trying my hand at incorporating time-dependent variables in cox proportional hazard modeling through the counting process.

 

I am up to the first step - creating indicator variables to tell me when the "nlr" status changes:

 

DATA change;
SET change;
ARRAY nlr_(*) nlr_0-nlr_3; *call in the time-varying nlr variables;
ARRAY chng(3); *the new indicator variables;
t=1; *initialise the position variable for the indicator variables;
DO i = 1 to 3;
if nlr_(i) NE nlr_(i-1) THEN DO; *detects whether there is a change in nlr status;
chng(t) = i-1; *assigns the last timept the status remained constant;
t=t+1;
END;
END;
RUN;

 

However, this message is popping up in my log - 

ERROR: Array subscript out of range at line 2863 column 20.

 

This is from the change dataset:

subjid3nlr_0nlr_1nlr_2nlr_3
A10000
A101001
A1000000

 

And I am aiming for it to look like this:

subjid3chng1chng2chng3nlr_0nlr_1nlr_2nlr_3
A1...0000
A10..21001
A100...0000

 

Not sure what I am doing wrong - appreciate any input (sorry am a beginner at this!)

1 ACCEPTED SOLUTION

Accepted Solutions
BrunoMueller
SAS Super FREQ

Arrays in SAS are 1 based, so the first element is accessed like arrayName{1}, so in your loop you try to get an array element as arrayName{1-1} which makes it 0, so this is way you get the error.

 

 

View solution in original post

3 REPLIES 3
BrunoMueller
SAS Super FREQ

Arrays in SAS are 1 based, so the first element is accessed like arrayName{1}, so in your loop you try to get an array element as arrayName{1-1} which makes it 0, so this is way you get the error.

 

 

Kurt_Bremser
Super User

Since you iterate over 3 values, but also use i-1 to access an array element, you in fact try to access four array elements in arrays that only have three elements.

Your code needs to take care of the border cases.

 

Whenever an out-of-range error like this happens, you also get a list of all current variable values. Inspect that, and you'll see what happens.

Astounding
Opal | Level 21

The simplest change I would recommend is to change one of the array definitions.  What you have now:

 

ARRAY nlr_(*) nlr_0-nlr_3;

 

What it should look like:

 

ARRAY nlr_ (0:3) nlr_0-nlr_3;

 

But for the life of me I can't figure out how you are getting values for the CHNG variables and why you want the values that you illustrate.  So that question will arise once you get past the errors.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

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. 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 42610 views
  • 2 likes
  • 4 in conversation