How to: |
The STRAN function substitutes a substring for another substring in a character string. STRAN enables you to edit part of a character string without replacing the field entirely.
To use this function, import the function library MNTUWS. For more information on importing this library see Calling a Function.
STRAN(string, substr1, substr2)
where:
Alphanumeric
Is the character string into which you want to substitute one substring for another, or a temporary field that contains the string.
Alphanumeric
Is the substring to replace.
Alphanumeric
Is the substring to insert in place of substr1.
STRAN replaces the word DOOR with the word Seater in the MODEL field:
MAINTAIN FILE CAR MODULE IMPORT (MNTUWS); FOR ALL NEXT COUNTRY CAR MODEL INTO XSTK WHERE MODEL CONTAINS 'DOOR' COMPUTE XSTK.NEWMOD/A24; COMPUTE I/I2=1; REPEAT XSTK.FOCCOUNT COMPUTE XSTK(I).NEWMOD=STRAN(XSTK(I).MODEL,'DOOR','SEATER'); TYPE "<<XSTK(I).CAR <<XSTK(I).MODEL <<XSTK(I).NEWMOD" COMPUTE I=I+1; ENDREPEAT END
The following are sample values for MODEL and values for the result of the STRAN function:
CAR MODEL STRAN --- ----- ----- PEUGEOT 504 4 DOOR 504 4 SEATER ALFA ROMEO 2000 4 DOOR BERLINA 2000 4 SEATER BERLINA MASERATI DORA 2 DOOR DORA 2 SEATER DATSUN B210 2 DOOR AUTO B210 2 SEATER AUTO TOYOTA COROLLA 4 DOOR DIX AUTO COROLLA 4 SEATER DIX AUT AUDI 100 LS 2 DOOR AUTO 100 LS 2 SEATER AUTO BMW 2002 2 DOOR 2002 2 SEATER BMW 2002 2 DOOR AUTO 2002 2 SEATER AUTO BMW 3.0 SI 4 DOOR 3.0 SI 4 SEATER BMW 3.0 SI 4 DOOR AUTO 3.0 SI 4 SEATER AUTO BMW 530I 4 DOOR 530I 4 SEATER BMW 530I 4 DOOR AUTO 530I 4 SEATER AUTO