Transforming Data with SAS Functions | |
Modifying Character Values with
Functions![]() ![]() |
![]() |
INDEX Function
The INDEX function enables you to search a character value for a specified string.
For example, suppose you need to search the values of the variable
|
SAS Data Set Hrd.Temp
Job | Contact | Department | Site |
word processing | WORD PROCESSOR | DP | 26 |
filing, administrative duties | ADMIN. ASST. | PURH | 57 |
organizational dev. specialist | CONSULTANT | PERS | 34 |
The INDEX function can complete this search. |
General form, INDEX function:
where
|
To search for the occurrence of word processing in the values
of the variable Job , you write the INDEX function as shown below.
Note that the character string appears within quotation marks.
index(job,'word processing') Then to create the new data set, include the INDEX function in a subsetting IF statement. Only those observations in which the function locates the string and returns a value greater than 0 are written to the data set. data hrd.datapool; set hrd.temp; if index(job,'word processing') > 0; run; Here's your data set that shows the temporary employees who have word processing experience. |
SAS Data Set Hrd.Datapool
Job | Contact | Department | Site |
word processing | WORD PROCESSOR | DP | 26 |
bookkeeping, word processing | BOOKKEEPER AST | BK | 57 |
word processing, sec. work | WORD PROCESSOR | DP | 95 |
bookkeeping, word processing | BOOKKEEPER AST | BK | 44 |
word processing | WORD PROCESSOR | DP | 59 |
word processing, sec. work | WORD PROCESSOR | PUB | 38 |
word processing | WORD PROCESSOR | DP | 44 |
word processing | WORD PROCESSOR | DP | 90 |
![]() ![]() ![]() ![]() ![]() ![]() |
|
![]() |
![]() |
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.