SAS | COMPRESS Function with Examples Last Updated : 29 Jul, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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: SQL 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: SQL 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. Examples: Example 1: Compressing Lowercase Letters SQL data _null_; x='456-123-852 A 123-8910 c'; y=compress(x, 'ABCD', 'l'); put string=; run; Output string= 456-123-852 123-8910 Example 2: Compressing Space Characters SQL data one; x='1 9 3 4 5 6 8'; y=compress(x,, 's'); put string=; run; Output string= 1934568 Example 3: Keeping Characters in the List SQL data one; x='Chemistry A Maths B Physics C'; y=compress(x, 'ABCD', 'k'); put string=; run; Output string= ABC Example 4: Compressing a String and Returning a Length of 0 SQL data _null_; x=''; len=lengthn(compress(x)); put len=; run; Output len= 0 Comment More infoAdvertise with us Next Article SAS | How to read character using Ampersand(&) S ShubhamMaurya3 Follow Improve Article Tags : Software Engineering SAS Programming Similar Reads SAS | COALESCE Function with Examples The COALESCE function is employed to pick the first non-missing value in a list of variables. In other words, it returns the first non-blank value of each row. Let's produce a sample dataset in SAS to know how COALESCE perform. Example: SQL data temp; input roll_no a1-a4; cards;12 . 98 52 . 23 79 . 2 min read How to create a function in MATLAB ? A function is a block of statements that intend to perform a specific task. Functions allow the users to reuse the code frequently. MATLAB has several predefined functions which are ready to use such as sin(), fact(), cos() etc. MATLAB also allows the users to define their own functions. Syntax: fun 2 min read How to import data into SAS? Entering Data Directly: You can enter numbers of lines of data directly in SAS program by using a DATALINES statement. The keywords are as follows: DATA: The DATA step always starts with a DATA statement. The purpose of the DATA statement is to tell SAS that you are creating a new data set i.e. outd 3 min read SAS | How to read character using Ampersand(&) We can use ampersand (&) to notify SAS to read the variable until there are two or more spaces encounter as a delimiter. This technique is always useful when the variable contains two or more words. For example: Actual Input: "Geeks for Geeks" Expected Input: "GeeksforGeeks" Example 1: There are 1 min read SAS Full Form SAS (Statistical Analysis System) is a comprehensive software suite developed by SAS Institute Inc., used globally for advanced analytics, business intelligence, data management, and predictive analytics. Developed between 1966 and 1976, SAS has evolved with advanced statistical techniques, point-an 4 min read If-Then-Else statement in SAS Programming Comparison Operators used while using conditional statements. Symbol Mnemonic Meaning = EQ equals ^= or ~= NE not equal > GT greater than < LT less than >= GE greater than or equals <= LE less than or equals in IN selecting multiple values IF statement Syntax: IF (condition is true) = 3 min read Like