Help using Base SAS procedures

Array Subset Out Of Range - n00b

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

Array Subset Out Of Range - n00b

[ Edited ]

 First time posting on the discussion boards here (I believe). 

 

I continue to encounter the error: "ERROR: Array subscript out of range at line 61 column 31."

 

The code is as follows:

 

data conversion;
set work.combo2;
array original_variables{7} rawsug refsug HFCS glucose dextrose total totalsweet;
array conversion_variables{7} rawsug_tbsp refsug_tbsp HFCS_tbsp glucose_tbsp dextrose_tbsp total_tbsp totalsweet_tbsp;
do vars= 1-7;
	conversion_variables{vars} = original_variables{vars}/3; /* This is line 61*/
end;
drop vars;
run;

And the exact error message:
 
 
ERROR: Array subscript out of range at line 61 column 31.
 Year=1970 Grains=6.93 Dairy=1.81 Meat_Fish=3.25 Vegetables=3.29 Fruits=1.12 Uspop=205.052 RawSug=37.112167365 RefSug=34.684268565
 HFCS=0.1867832418 Glucose=4.7409189704 Dextrose=1.5663774862 Total=6.4940796983 Syrup=0.1695530355 Honey=0.3424306404
 TotalSweet=41.690331939 rawsug_tbsp=. refsug_tbsp=. HFCS_tbsp=. glucose_tbsp=. dextrose_tbsp=. total_tbsp=. totalsweet_tbsp=.
 vars=-6 _ERROR_=1 _N_=1
 
I'm using an example from Section 13.5 "Learning SAS By Example" as my template and it seems like this should work. is there something I am missing?
 
Thanks for taking the time to review. 

Accepted Solutions
Solution
‎12-11-2016 12:56 PM
Super User
Posts: 17,743

Re: Array Subset Out Of Range - n00b

Looking at the error you can see VARS=-6

 

Your do statement is incorrect and resolves to

 

do vars=1-7 -> do vars=-6

 

You want

 

do vars=1 to 7;

View solution in original post


All Replies
Solution
‎12-11-2016 12:56 PM
Super User
Posts: 17,743

Re: Array Subset Out Of Range - n00b

Looking at the error you can see VARS=-6

 

Your do statement is incorrect and resolves to

 

do vars=1-7 -> do vars=-6

 

You want

 

do vars=1 to 7;

Occasional Contributor
Posts: 8

Re: Array Subset Out Of Range - n00b

[ Edited ]

Thank you for the quick reply. It is much appreciated. 

 

EDIT: That fix worked perfectly!

☑ This topic is SOLVED.

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

Discussion stats
  • 2 replies
  • 231 views
  • 1 like
  • 2 in conversation