7SAS® ADVANCED PROGRAMMING TOPICS PART 2

This chapter continues with the presentation of topics that are useful in preparing a data set for analysis. The topics here are designed to provide greater flexibility in constructing SAS programs. Using these techniques can simplify coding for tasks that involve repeated or related observations.

7.1 USING SAS ARRAYS

A SAS ARRAY statement provides a method for placing a series of observations into a single variable called an array. Often these variables are referenced as part of a DO loop, which is a technique for iterating through a set of data. (DO loops are presented in the following section of this chapter.) A simplified syntax for SAS arrays is the following:

ARRAY ARRAY-NAME(SUBSCRIPT) <$> ARRAY-VALUES

One-dimensional arrays are specified with an ARRAY statement, such as

ARRAY TIME(1:6) TIME1-TIME6;

This ARRAY statement creates a one-dimensional array called TIME1 with an index value indicated in a parenthesis so TIME(1)=TIME1, TIME(2)=TIME2, and so on. In this case, six values are assigned to the values TIME(1) through TIME(6). Here are some more ways to create an ARRAY:

  1. ARRAY TIME(6) TIME1-TIME6;

    The result is the same as the previous example.

ARRAY TIME(0:5) A B C D E F;
  1. TIME(0)=A, TIME(1)=B, and ...

Get SAS Essentials: Mastering SAS for Data Analytics, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.