O'Reilly logo

SAS Essentials: Mastering SAS for Data Analytics, 2nd Edition by Wayne A. Woodward, Alan C. Elliott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required