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:
subjid3 | nlr_0 | nlr_1 | nlr_2 | nlr_3 |
A1 | 0 | 0 | 0 | 0 |
A10 | 1 | 0 | 0 | 1 |
A100 | 0 | 0 | 0 | 0 |
And I am aiming for it to look like this:
subjid3 | chng1 | chng2 | chng3 | nlr_0 | nlr_1 | nlr_2 | nlr_3 |
A1 | . | . | . | 0 | 0 | 0 | 0 |
A10 | . | . | 2 | 1 | 0 | 0 | 1 |
A100 | . | . | . | 0 | 0 | 0 | 0 |
Not sure what I am doing wrong - appreciate any input (sorry am a beginner at this!)
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.
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.
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.
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.
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!
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.
Ready to level-up your skills? Choose your own adventure.