From the course: SAS® 9.4 Cert Prep: Part 04 Preparing Data

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Creating character columns with the LENGTH statement

Creating character columns with the LENGTH statement - SAS Tutorial

From the course: SAS® 9.4 Cert Prep: Part 04 Preparing Data

Creating character columns with the LENGTH statement

- [Instructor] You can also use conditional processing to create character columns. Remember that the columns in an output table are defined in the compilation phase of the data step. When SAS read through the code, the first occurrence of a column defines the name, type and length of a column. SAS isn't processing the conditional logic when it compiles the code. It just sees the assignment statement. And as programed the first assignment statement defines a character column and assigns the value "Basic." So SAS creates a column named "CarType" with a length of five, the number of characters in the word "Basic." You can see in the output table the word "Luxury" is truncated because it has six characters. One way to avoid this problem is to explicitly define a character column in the data step with a length statement. The syntax for this statement is the keyword "LENGTH" followed by the name of the column, a dollar sign…

Contents