Transforming Data with SAS Functions | |
Modifying Character Values with
Functions![]() ![]() |
![]() |
SUBSTR Function
The SUBSTR function can be used to
Let's begin with the task of extracting a portion of a value. In the data
set Hrd.Newtemp, the names of temporary employees are stored
in three name variables, |
SAS Data Set Hrd.Newtemp
Agency | ID | LastName | FirstName | MiddleName |
Administrative Support, Inc. | F274 | CICHOCK | ELIZABETH | MARIE |
Administrative Support, Inc. | F101 | BENINCASA | HANNAH | LEE |
OD Consulting, Inc. | F054 | SHERE | BRIAN | THOMAS |
New Time Temps Agency | F077 | HODNOFF | RICHARD | LEE |
However, you decide to modify the data set to store only the middle initial
instead of the full middle name. To do so, you must extract the first letter
of the middle name values and assign these values to the new variable
MiddleInitial . |
SAS Data Set Work.Newtemp
Agency | ID | LastName | FirstName | MiddleInitial |
Administrative Support, Inc. | F274 | CICHOCK | ELIZABETH | M |
Administrative Support, Inc. | F101 | BENINCASA | HANNAH | L |
OD Consulting, Inc. | F054 | SHERE | BRIAN | T |
New Time Temps Agency | F077 | HODNOFF | RICHARD | L |
The SUBSTR function enables you to extract any number of characters from a character string, starting at a specified position in the string. |
General form, SUBSTR function:
where
|
![]() ![]() ![]() ![]() ![]() ![]() |
|
![]() |
![]() |
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.