Problem with a macro Array subscript out of range.

Accepted Solution Solved
Reply
Contributor
Posts: 32
Accepted Solution

Problem with a macro Array subscript out of range.

Anyone have any idea why I'm having an issue (Array subscript out of range error) with the following code? All the required variables are there. The syntax looks right. Any clues?

%MACRO GENFLOWVAR;

DATA TMP_FA2; SET TMP_FA2;

ARRAY FLOWS FLOW0-FLOW33;

ARRAY FS F0-F33;

%DO I= 3 %TO 30; 

FLOWS[&I]=MEAN(FS[%EVAL(&I-3)],FS[%EVAL(&I-2)],FS[&I],FS[%EVAL(&I+1)],FS[%EVAL(&I+2)],FS[%EVAL(&I+3)]);

%END;

%MEND;%GENFLOWVAR;


Accepted Solutions
Solution
‎07-01-2014 01:23 PM
Super User
Posts: 11,343

Re: Problem with a macro Array subscript out of range.

why are you using a macro do loop???? There is no need;

do i = 3 to 30;

FLOWS=MEAN(FS[i-3],FS[I-2],FS,FS[I+1],FS[I+2],FS[i+3];

end;

should work just fine.

add options mprint; before your macro call %genflowvar and examine the resulting generated code.

View solution in original post


All Replies
Solution
‎07-01-2014 01:23 PM
Super User
Posts: 11,343

Re: Problem with a macro Array subscript out of range.

why are you using a macro do loop???? There is no need;

do i = 3 to 30;

FLOWS=MEAN(FS[i-3],FS[I-2],FS,FS[I+1],FS[I+2],FS[i+3];

end;

should work just fine.

add options mprint; before your macro call %genflowvar and examine the resulting generated code.

Contributor
Posts: 32

Re: Problem with a macro Array subscript out of range.

Thanks for the help

SAS Employee
Posts: 15

Re: Problem with a macro Array subscript out of range.

Without your source data it's difficult to say, but note:

  1. This code will not generate FLOWS[0], FLOWS[1], or FLOWS[2].
  2. Your data step is not terminated by a run statement.
Contributor
Posts: 32

Re: Problem with a macro Array subscript out of range.

Posted in reply to JasonAllen

Thanks for the help.

Super User
Posts: 5,496

Re: Problem with a macro Array subscript out of range.

The array elements are named F0-F33, but the array subscript still has to range from 1 to 34, not from 0 to 33.  It is illegal (array subscript out of range) to ask for FS[0] in your program.  If you would like the array subscript to range from 0 to 33, you have to define the array slightly differently:

array FS {0:33} FS0-FS33;

Contributor
Posts: 32

Re: Problem with a macro Array subscript out of range.

Posted in reply to Astounding

Thanks for the help

🔒 This topic is solved and locked.

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

Discussion stats
  • 6 replies
  • 441 views
  • 6 likes
  • 4 in conversation