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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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);

 

View solution in original post

7 REPLIES 7
ChrisNZ
Tourmaline | Level 20

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.

FrustratedBio
Calcite | Level 5
Okay, what youre saying kinda makes sense kinda doesn't....I'm just faking it til i make it with 3 weeks left in this insufferable class. I'm just not sure how this error is coming about as I used a format technique in the last assignment problem that worked just fine.

ERROR: Array subscript out of range at line 91 column 15.
Customer_ID=5 Month1=213.1 Month2=. Month3=478 Month4=525.8 Month5=394.35 Month6=191.79 Over1=13.1 Over2=. Over3=178 Over4=425.8
Over5=294.35 Over6=-8.21 Total_Over=903.04 _I_=. _temporary_=200 i=2 _ERROR_=1 _N_=1
NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line):(Column).
1 at 80:13
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 1 observations read from the data set BST5030.ORDERS_MIDYEAR.
WARNING: The data set WORK.PREFERRED_CUST may be incomplete. When this step was stopped there were 0 observations and 8 variables.
WARNING: Data set WORK.PREFERRED_CUST was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.02 seconds
ChrisNZ
Tourmaline | Level 20

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?

FrustratedBio
Calcite | Level 5
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 libname bst5030 '/folders/myfolders/sasuser.v94/Data for classes 8 to 11 (2)';
NOTE: Libref BST5030 refers to the same physical library as _TEMP0.
NOTE: Libref BST5030 was successfully assigned as follows:
Engine: V9
Physical Name: /folders/myfolders/sasuser.v94/Data for classes 8 to 11 (2)
74 data preferred_cust;
75 set bst5030.orders_midyear;
NOTE: Data file BST5030.ORDERS_MIDYEAR.DATA is in a format that is native to another host, or the file encoding does not match the
session encoding. Cross Environment Data Access will be used, which might require additional CPU resources and might reduce
performance.
76
77 keep Customer_ID Over1-Over6 Total_Over;
78 array Mon{6} Month1-Month6;
79 Over1=Month1-200;
80 Over2=Month2-400;
81 Over3=Month3-300;
82 Over4=Month4-100;
83 Over5=Month5-100;
84 Over6=Month6-200;
85
86 array Target _temporary_ (200, 400, 300, 100, 100, 200);
WARNING: Too many values for initialization of the array Target. Excess values are ignored.
87
88 array ov {6} Over1-Over6;
89 do i=1 to 6;
90 Ov{i}=Mon{i}-Target{i};
91 end;
92
93 Total_Over=sum(of Over1-Over6);
94 run;

ERROR: Array subscript out of range at line 90 column 15.
Customer_ID=5 Month1=213.1 Month2=. Month3=478 Month4=525.8 Month5=394.35 Month6=191.79 Over1=13.1 Over2=. Over3=178 Over4=425.8
Over5=294.35 Over6=-8.21 _I_=. _temporary_=200 i=2 Total_Over=. _ERROR_=1 _N_=1
NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line):(Column).
1 at 80:13
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 1 observations read from the data set BST5030.ORDERS_MIDYEAR.
WARNING: The data set WORK.PREFERRED_CUST may be incomplete. When this step was stopped there were 0 observations and 8 variables.
WARNING: Data set WORK.PREFERRED_CUST was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.02 seconds


95 proc print data=preferred_cust noobs;
96 run;

NOTE: No observations in data set WORK.PREFERRED_CUST.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds


97
98 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
110
Tom
Super User Tom
Super User

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.

 

 

Tom
Super User Tom
Super User

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);

 

FrustratedBio
Calcite | Level 5
Such an easy fix. Good thing I ain't majoring in this. Thanks!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 7 replies
  • 745 views
  • 0 likes
  • 3 in conversation