Help using Base SAS procedures

Error: Array subscript out of range

Accepted Solution Solved
Reply
Contributor
Posts: 22
Accepted Solution

Error: Array subscript out of range

Hello all! I know there are a ton of "subscript out of range" posts on here, but none of them have helped me identify my problem...

 

data want;
data have;
array barriers(19) $ unawareneed_86 unawarelaterdose_86 unawaretimeplace_86 fearsideeffects_86 longdistanceimmsite_86 toobusy_86 nopermission_86 postponed_86 heardneg_86 timeinconvenient_86 vaccinatorabsent_86 vaccinena_86 famprob_86 childillnottaken_86 childilltakendidnotreceive_86 lackoffaithinimm_86 longwaittime_86 lackoftrustinstaff_86 other_86; array barriercited(19) barriercited1-barriercited19; do i=1 to 19; if barriers(i)='Yes' then barriercited(i)=1; else if barriers(i)='No' then vacchx(i)=0; end; numberbarriers=sum(of barriercited(*)); run;

I keep getting this error: "ERROR: Array subscript out of range at line 13972 column 43" (although the numbers tend to change when I re-run it each time. Hoping fresh eyes will help! Thanks!


Accepted Solutions
Solution
‎02-25-2016 05:18 PM
Super User
Posts: 17,958

Re: Error: Array subscript out of range

else if barriers(i)='No' then vacchx(i)=0;

 

You're referencing another array that doesn't seem to be declared anywhere.

View solution in original post


All Replies
Solution
‎02-25-2016 05:18 PM
Super User
Posts: 17,958

Re: Error: Array subscript out of range

else if barriers(i)='No' then vacchx(i)=0;

 

You're referencing another array that doesn't seem to be declared anywhere.

Contributor
Posts: 22

Re: Error: Array subscript out of range

I noticed that literally as soon as I posted the discussion - I thought I deleted it. Guess that's what I get for copy/paste. Thanks though!

Trusted Advisor
Posts: 1,115

Re: Error: Array subscript out of range

The error messages from an undeclared array are different, though.

ERROR: Undeclared array referenced: vacchx.
ERROR: Variable vacchx has not been declared as an array.

So, I'm not sure how this mistake could explain the "subscript out of range" message.

Super User
Posts: 5,099

Re: Error: Array subscript out of range

Most likely, you will need to post your actual program.  It's not just the reference to a nonexistent array, it's also that  you have a second DATA statement instead of a SET statement.  While you've posted all the code that seems relevant from your perspective, "fresh eyes" will need to see the whole program to diagnose this.

Contributor
Posts: 22

Re: Error: Array subscript out of range

Sorry all - it was as @Reeza pointed out and my arrays didn't match. Thank you though!

☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 1558 views
  • 1 like
  • 4 in conversation