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

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
Quartz | Level 8

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.

SAS Innovate 2025: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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