Transforming Data with SAS Functions | |
Modifying Character Values with
Functions![]() ![]() |
![]() |
Using the SUBSTR function, you can extract the first letter of the
MiddleName value to create the new variable MiddleInitial . |
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 |
You write the SUBSTR function as:
substr(middlename,1,1)
This function specifies that a character string be extracted from the value
of data work.newtemp(drop=middlename); set hrd.newtemp; MiddleInitial=substr(middlename,1,1); run;
Notice that the |
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 |
Using the SUBSTR function, you can extract a substring from any character value if you know the position of the substring. |
![]() ![]() ![]() ![]() ![]() ![]() |
|
![]() |
![]() |
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.