SAS | COMPRESS Function with Examples
COMPRESS function is basically used to compress/removes all the spaces/blanks in a character string. In other words, it removes leading, between and trailing spaces from the strings.
The COMPRESS function allows null arguments. A null argument is treated as a string that features a length of zero.
Example:
Input: " Geeks For Geeks "
Output: "Geeksforgeeks"
Input: null
Output: null
Syntax:
COMPRESS(String, characters to be removed, Modifier)
Program:
- Sample dataset:
Data char ;
Input Name $ 1-50 ;
Cards;
Geeks for Geeks
GeeksforGeeks
Ge eks for Geeks
Geeks f or Geeks
;
Run;
|
Sample Data Output:
- Using COMPRESS function on sample data defined above:
Data char1;
Set char ;
char1 = compress( Name );
run;
|
Output
- Remove specific characters
In SAS, the additional parameter referred to as MODIFIER was added to the function.
The following keywords can be used as modifiers-
-
a – Remove all upper and lower case characters from String.
-
ak – Keep only alphabets from String.
-
kd – Keeps only numeric values
-
d – Remove numerical values from String.
-
i – Remove specified characters both upper and lower case from String.
-
k – keeps the specified characters in the string instead of removing them.
-
l – Remove lowercase characters from String.
-
p – Remove Punctuation characters from String.
-
s – Remove spaces from String. This is default.
-
u – Remove uppercase characters from String.
Last Updated :
29 Jul, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...