SAS String Functions

SCAN/COMPRESS/COMPBL

SCAN(string, count<,charlist <,modifiers>>)

Column: deptname
‘AB-Department X’
‘CD-Department Y’

data faculty;
set admin1516;
where divdesc = “Faculties”;
length fac $4.;
fac = scan(deptname, 1, ‘-‘);
run;

New Column: fac
‘AB’
‘CD’

COMPRESS(source<, chars><, modifiers>)

compress all the blanks

a= ‘A  B    C  D’

b= compress(a)

results for b is : ‘ABCD’

COMPBL: removes multiple blanks

a= ‘A  B  C D ‘

b= compbl(a)

results for b is : ‘A B C D’