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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

6 REPLIES 6
ballardw
Super User

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.

kodmfl
Obsidian | Level 7

Thanks for the help

JasonAllen
SAS Employee

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.
kodmfl
Obsidian | Level 7

Thanks for the help.

Astounding
PROC Star

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;

kodmfl
Obsidian | Level 7

Thanks for the help

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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