Help using Base SAS procedures

Array subscript out of range

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 11
Accepted Solution

Array subscript out of range

Hi team, 

I have a dataset that looks like this: 

ID DIABETES CHF_FU DM_FU

1     1                  21            19

2     .                   10             .

3     1                  19            12. 

4     .                   19             .

5     1                   7              0

 

CHF_FU is the total follow-up time and DM_FU is the time that diabetes was diagnosed. I am trying to create a time-to-event data that has multiple columns per year of follow-up for diabetes. I used the following code: 

proc sort data = merged;
   by descending CHF_FU;
run;

data _NULL_;
   set merged;
   if _N_=1 then call symput('cols',CHF_FU);
run;

%put Additional Columns: &cols;

proc sort data = merged;   
   by ID;
run;

data merged1;
   set merged;

   array period[&cols];
   
   i = 1;
   do until (i > CHF_FU);
      period[i] = 0;
      i + 1;
   end;

   if not missing(DM_FU) then do j = DM_FU to CHF_FU;
      period[j] = 1;
   end;

   drop i j;
run;

It seems to be working for the first 4 rows but generates the error message 'Array subscript out of range' when it gets to the fifth row. The fifth row belongs to an individual that has diabetes but diabetes was present at baseline (hence the DM_FU of zero). 

I cannot figure out what the problem is. Any ideas?


Accepted Solutions
Solution
‎06-04-2017 12:17 AM
Trusted Advisor
Posts: 1,584

Re: Array subscript out of range

[ Edited ]

Change line:

if not missing(DM_FU) then do j = DM_FU to CHF_FU;

into:

if DM_FU > CHF_FU then do; 
   put '*** Data Error: DM_FU > CHF_FU';
   abort;
end;

if DM_FU>0 then do j = DM_FU to CHF_FU;

pay attention: zero is greater then missing and zero is not a vaild index;

 

Alternativley define an array of {&cols+1} and use index (i+1) in order

that base=0 will use index 1.

View solution in original post


All Replies
Solution
‎06-04-2017 12:17 AM
Trusted Advisor
Posts: 1,584

Re: Array subscript out of range

[ Edited ]

Change line:

if not missing(DM_FU) then do j = DM_FU to CHF_FU;

into:

if DM_FU > CHF_FU then do; 
   put '*** Data Error: DM_FU > CHF_FU';
   abort;
end;

if DM_FU>0 then do j = DM_FU to CHF_FU;

pay attention: zero is greater then missing and zero is not a vaild index;

 

Alternativley define an array of {&cols+1} and use index (i+1) in order

that base=0 will use index 1.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 388 views
  • 2 likes
  • 2 in conversation