Introduction

In DATA step programming, you often need to perform the same action on more than one variable. Although you can process variables individually, it is easier to handle them as a group. You can do this by using array processing.

For example, using an array and DO loop, the program below eliminates the need for 365 separate programming statements to convert the daily temperature from Fahrenheit to Celsius for the year.

     data work.report(drop=i);
        set master.temps;
        array daytemp{365} day1-day365;
        do i=1 to 365;
           daytemp{i}=5*(daytemp{i}-32)/9;
        end;
     run;

You can use arrays to simplify the code needed to

  • perform repetitive calculations
  • create many variables that have the same attributes
  • read data
  • rotate SAS data sets by changing variables to observations or observations to variables
  • compare variables
  • perform a table lookup.
This lesson teaches you how to define an array and how to reference elements of the array in the DATA step.


1.5 hours



In this lesson, you learn to

  • group variables into one- and two-dimensional arrays
  • perform an action on array elements
  • create new variables with an ARRAY statement
  • assign initial values to array elements
  • create temporary array elements with an ARRAY statement.

complete the following lessons:

  • .