Amadeus cookies policy - you'll see this message only once.

Amadeus use cookies on this website. They help us to know a little bit about you and how you use our website, which improves the browsing experience and marketing - both for you and for others. They are stored locally on your computer or mobile device. To accept cookies, continue browsing as normal. Or, go to the privacy policy for more information.

The Enhanced COMPRESS Function

The COMPRESS function has been enhanced in SAS 9 by providing an optional 3rd argument, which controls the functions behaviour.

The list of modifiers that can be specified in the third argument includes 'K' to 'Keep' what ever you specify in the functions second argument, instead of removing it. The 'U' modifier will act on 'Uppercase' letters only and the 'L' modifier on lowercase. 'P' will only act on 'Punctuation' characters found in the text and 'D' will act on digits. See examples below:

data _null_;
  text_string="this is 'a' string of text 12345.";
  * Example 1: Keep occurences of 's' in the character string;
  cmp_text1 = compress(text_string,'s','K');
  * Example 2: Remove all digits from the character string;
  cmp_text2 = compress(text_string,,'D');
  * Example 3: Remove punctuation from the character string;
  cmp_text3 = compress(text_string,,'P');
  * Example 4: Remove uppercase characters from the character
  cmp_text4 = compress(text_string,,'U');
  * Example 5: Keep occurences of 's', digits, punctuation 
               and uppercase characters in the character string;
  cmp_text5 = compress(text_string,'s','KDPU');
  put (_all_)(=/);

This log file produced when submitting this step is as follows:

text_string=this is 'a' string of text 12345.
cmp_text2=this is 'a' string of text .
cmp_text3=this is a string of text 12345
cmp_text4=this is 'a' string of text 12345.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds