Receiving error: Array subscript out of range

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Receiving error: Array subscript out of range

Hello,

 

I'm having trouble debugging my error and could really use some help. Here is my code with the line numbers and I keep getting the error: Array subscript out of range.

 

2060 data prescribercount (keep=patientid prescribers1 prescribers2);
2061 set prescriptions1;
2062 by patientid half prescriber;
2063 array prescribers(2) prescribers1 prescribers2;
2064 retain prescribers1-prescribers2 0;
2065 if first.prescriber then prescribers(half)=prescribers(half)+1;
2066 else if last.patientid then do;
2067 output;
2068 prescribers1=0;
2069 prescribers2=0;
2070 end;
2071 run;

ERROR: Array subscript out of range at line 2065 column 44.

 

Would really appreciate insights.

 

Thanks!!


Accepted Solutions
Solution
‎05-07-2018 10:42 AM
Super User
Posts: 13,508

Re: Receiving error: Array subscript out of range

What values does your variable HALF take on?

Your array definition sets the array to only accept 1 and 2. If half ever has any other value that will cause the error.

 

Run proc freq on the input data set and the variable Half to confirm what you might believe.

View solution in original post


All Replies
Solution
‎05-07-2018 10:42 AM
Super User
Posts: 13,508

Re: Receiving error: Array subscript out of range

What values does your variable HALF take on?

Your array definition sets the array to only accept 1 and 2. If half ever has any other value that will cause the error.

 

Run proc freq on the input data set and the variable Half to confirm what you might believe.

New Contributor
Posts: 2

Re: Receiving error: Array subscript out of range

Thank you!! You were right. It turned out that HALF had all missing variables. The variable names in a previous code didn't match what was supposed to be in this SAS code and thus HALF didn't get coded properly.

 

Appreciate your prompt support!

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 100 views
  • 0 likes
  • 2 in conversation