SAS String Function COMPRESS( )

This has been demonstrated below;

1. SAS COMPRESS( ) Function

SYNTAX: COMPRESS(char_stirng, 'char_list_to_be_removed'<optional>);

<< Go Back To SAS String Functions

SAS COMPRESS () Function is used to remove given characters from the string. Users have the facility to remove a single specific character or a group of characters from the target string. All they have to do is provide the list of characters to be removed as second argument to the function.

However this second argument is optional to the function and in absense of this; COMPRESS() function will remove all BLANKS from the given string.

Example: SAS COMPRESS( ) Function

SAS Code:

data temp;

ph_no = "011- 22 33344(1212)";

ph_no_without_blanks = COMPRESS(ph_no);

ph_no_only_numbers = COMPRESS(ph_no, ' ()-');

/* Note the second argument to the function as list

of characters to be removed */

run;

proc print data = temp;

run;

PROC PRINT OUTPUT :

* Please note this code has compiled on SAS 9.2 Platform.

At the first statement

ph_no_without_blanks = COMPRESS(ph_no);

Where we haven’t supplied the second argument to the function we can observe that COMPRESS () has removed all the blanks from the string.

While at the Second Statement

ph_no_only_numbers = COMPRESS(ph_no, ' ()-');

We have supplied the list of characters enclosed in single quote including BLANK character; and hence removed all the individual occurrences of these characters.

<< Go Back To SAS String Functions