So below is the code that I am using. The part that I seem to be getting toruble from is array ov. When I run the program I get an error reading "ERROR: Array subscript out of range at line 91 column 15." I'm having a hard time underatanding what this means, and explanations that I have read online haven't really helped, so please explain in layman terms.
libname bst5030 '/folders/myfolders/sasuser.v94/Data for classes 8 to 11 (2)';
data preferred_cust;
set bst5030.orders_midyear;
keep Customer_ID Over1-Over6 Total_Over;
array Mon{6} Month1-Month6;
Over1=Month1-200;
Over2=Month2-400;
Over3=Month3-300;
Over4=Month4-100;
Over5=Month5-100;
Over6=Month6-200;
Total_Over=sum(of Over1-Over6);
array Target _temporary_ (200, 400, 300, 100, 100, 200);
array ov {6} Over1-Over6;
do i=1 to 6;
Ov{i}=Mon{i}-Target{i};
end;
Total_Over=sum(of Over1-Over6);
run;
proc print data=preferred_cust noobs;
run;
This line is probably not doing what you thought:
array Target _temporary_ (200, 400, 300, 100, 100, 200);
Try it by itself.
3094 data test; 3095 array Target _temporary_ (200, 400, 300, 100, 100, 200); WARNING: Too many values for initialization of the array Target. Excess values are ignored. 3096 run; NOTE: The data set WORK.TEST has 1 observations and 1 variables. NOTE: DATA statement used (Total process time): real time 0.09 seconds cpu time 0.03 seconds
If you want to define a _temporary_ array you MUST tell it how many elements there are in the array. Since you did not SAS thought you wanted to make an array with only one variable named _TEMPORARY_.
array Target [6] _temporary_ (200, 400, 300, 100, 100, 200);
Look in the log at the value of variable I when this happens.
It is probably not an integer between 1 and 6 as expected,
Also note that you variable Total_Over is given a value twice; the first value will be discarded.
Same for variables Over1-Over6.
Show the whole step's log please.
We can't see what lines 80 or 91 are.
i=2 here, which is a value array index value.
Have you fixed the other errors as per my comments?
The first thing to do is read the error message. It tells you where it thinks the error is.
ERROR: Array subscript out of range at line 91 column 15.
So look a the log and see which line is listed as line 91. Then see what part of the line is the 15 character in the line.
Also look at the variables and their values. Did you notice you have defined a variable named _TEMPORARY_? Did you intend to do that?
Show more of the log, from the DATA statement to the errors and notes. And use the Insert Code button when pasting or editing the text to preserve its formatting.
This line is probably not doing what you thought:
array Target _temporary_ (200, 400, 300, 100, 100, 200);
Try it by itself.
3094 data test; 3095 array Target _temporary_ (200, 400, 300, 100, 100, 200); WARNING: Too many values for initialization of the array Target. Excess values are ignored. 3096 run; NOTE: The data set WORK.TEST has 1 observations and 1 variables. NOTE: DATA statement used (Total process time): real time 0.09 seconds cpu time 0.03 seconds
If you want to define a _temporary_ array you MUST tell it how many elements there are in the array. Since you did not SAS thought you wanted to make an array with only one variable named _TEMPORARY_.
array Target [6] _temporary_ (200, 400, 300, 100, 100, 200);
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.