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

Here's some simple code that exemplifies an issue I'm having:

 

data;
array grid (3,3) row1-row3 col1-col3;
run;

 

Here's the error message I receive:

 
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 data;
74 array grid (3,3) row1-row3 col1-col3;
ERROR: Too few variables defined for the dimension(s) specified for the array grid.
75 run;
 
What can possibly be wrong?
 
Thanks,
 
Gene
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

The specification is (Dimension1, Dimesnion2) with the total number of values being Dimension1 * Dimension 2.  

So for 3x3 you have 9 values, not 6 but you've only indicated 6 names. 

 

Here's two examples of code that does work:

 

data one;
	array _grid (2, 3) row1 - row3 col1-col3;

	do i=1 to 2;

		do j=1 to 3;
			_grid(i, j)=i*j;
		end;
	end;
run;

data two;
	array _grid (3, 2) row1 - row3 col1-col3;

	do i=1 to 3;

		do j=1 to 2;
			_grid(i, j)=i*j;
		end;
	end;
run;

@genemroz wrote:

Here's some simple code that exemplifies an issue I'm having:

 

data;
array grid (3,3) row1-row3 col1-col3;
run;

 

Here's the error message I receive:

 
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 data;
74 array grid (3,3) row1-row3 col1-col3;
ERROR: Too few variables defined for the dimension(s) specified for the array grid.
75 run;
 
What can possibly be wrong?
 
Thanks,
 
Gene

 

 

View solution in original post

3 REPLIES 3
Reeza
Super User

The specification is (Dimension1, Dimesnion2) with the total number of values being Dimension1 * Dimension 2.  

So for 3x3 you have 9 values, not 6 but you've only indicated 6 names. 

 

Here's two examples of code that does work:

 

data one;
	array _grid (2, 3) row1 - row3 col1-col3;

	do i=1 to 2;

		do j=1 to 3;
			_grid(i, j)=i*j;
		end;
	end;
run;

data two;
	array _grid (3, 2) row1 - row3 col1-col3;

	do i=1 to 3;

		do j=1 to 2;
			_grid(i, j)=i*j;
		end;
	end;
run;

@genemroz wrote:

Here's some simple code that exemplifies an issue I'm having:

 

data;
array grid (3,3) row1-row3 col1-col3;
run;

 

Here's the error message I receive:

 
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 data;
74 array grid (3,3) row1-row3 col1-col3;
ERROR: Too few variables defined for the dimension(s) specified for the array grid.
75 run;
 
What can possibly be wrong?
 
Thanks,
 
Gene

 

 

genemroz
Pyrite | Level 9

Hmm, OK.  I mistakenly thought the names were for rows and columns. Now I realize that they are the names of the elements of the array.  Thanks for straightening me out.

 

Gene

Reeza
Super User
An array in SAS is just shortcut reference to variables. There isn't an object created anywhere and it doesn't really "exist", except as a method of simplifying logic for the programmer. Occasionally, I've found a need for a multi-dimensional array but those times have been few and far between to be honest, they don't have a ton of value in SAS.
Develop Code with SAS Studio

Get started using SAS Studio to write, run and debug your SAS programs.

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