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.
Input: " Geeks For Geeks " Output: "Geeksforgeeks" Input: null Output: null
COMPRESS(String, characters to be removed, Modifier)
- Sample dataset:
$ 1-50 ;
- Using COMPRESS function on sample data defined above:
char1 = compress(
- 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.
- Example 1: Compressing Lowercase Letters
'456-123-852 A 123-8910 c'
string= 456-123-852 123-8910
- Example 2: Compressing Space Characters
'1 9 3 4 5 6 8'
- Example 3: Keeping Characters in the List
'Chemistry A Maths B Physics C'
- Example 4: Compressing a String and Returning a Length of 0
- SAS | COALESCE Function with Examples
- How to import data into SAS?
- Introduction to SAS programming
- How to import External Data from Excel or Text file into SAS Programming?
- How to Create or Modify a Variable in SAS Programming?
- Contains and Between-And operators in SAS Programming
- How to drop variables from a dataset in SAS Programming?
- Where Statement in SAS Programming
- If-Then-Else statement in SAS Programming
- IS MISSING and IS NOT MISSING Operators in SAS Programming
- Like Operator in SAS Programming
- SAS | How to specify a list of Variables?
- SAS | How to read character of varying length using COLON Modifier
- SAS | How to read character using Ampersand(&)
- SAS | Date Formats and Informats
- SAS | Delete Empty Rows
- SAS : How to Display Current Date?
- Java Swing | JSplitPane with Examples
- Java Swing | JComboBox with examples
- Java Swing | JCheckBox with examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.