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

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!!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

2 REPLIES 2
ballardw
Super User

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.

ashaikh
Calcite | Level 5

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!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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