Chapter 9
Working with Character Variables
Introduction to Working with Character Variables . . . . . . . . . . . . . . . . . . . . . . . . 129
Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
Character Variables in SAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
Input SAS Data Set for Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
Identifying Character Variables and Expressing Character Values . . . . . . . . . . . 131
Setting the Length of Character Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Handling Missing Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Reading Missing Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Checking for Missing Character Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Setting a Character Variable Value to Missing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Creating New Character Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Extracting a Portion of a Character Value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Combining Character Values: Using Concatenation . . . . . . . . . . . . . . . . . . . . . . . 139
Saving Storage Space by Treating Numbers as Characters . . . . . . . . . . . . . . . . . . 142
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Learning More . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Introduction to Working with Character Variables
Purpose
In this section, you will learn how to do the following:
identify character variables
set the length of character variables
align character values within character variables
handle missing values of character variables
work with character variables, character constants, and character expressions in SAS
program statements
129

Get Step-by-Step Programming with Base SAS 9.4, Second Edition, 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.