SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Processing Variables with Arrays
Creating Multidimensional Arrays


Understanding Multidimensional Arrays

So far, you have learned how to group variables into one-dimensional arrays. You can also group variables into table-like structures called multidimensional arrays. This section teaches you how to define and use two-dimensional arrays, which are a common type of multidimensional array.

Suppose you want to write a DATA step to check responses on a quiz against a master key of correct answers. As long as there is only one correct answer per question, the comparison is simply one to one.

     Resp1  Key1
     Resp2  Key2
     Resp3  Key3
     Resp4  Key4

However, if there is more than one correct answer per question, you must compare each response to each possible correct answer to see if there is a match.

     Resp1  Key1   Key2   Key3
     Resp2  Key4   Key5   Key6
     Resp3  Key7   Key8   Key9
     Resp4  Key10  Key11  Key12

You can process the above data more easily by grouping the answer key variables into a two-dimensional array. Just as you can think of a one-dimensional array as a single row of variables, for example . . .

     Key1 Key2 Key3 Key4 Key5 Key6 Key7 Key8 Key9 Key10 Key11 Key12
. . . you can think of a two-dimensional array as multiple rows of variables.
     Key1   Key2   Key3
     Key4   Key5   Key6
     Key7   Key8   Key9
     Key10  Key11  Key12

  back||next


Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.

Terms of Use & Legal Information | Privacy Statement