COMPRESS

Function: COMPRESS

Purpose: To remove specified characters from a character value. When used with k modifier , compress can be used to keep characters (such as digits) in a character value and remove everything else.

SyntaxCOMPRESS(character-value <,'compress-list'> <,'modifiers'>)

            character-value is any SAS character value.

compress-list  is an optional list of the characters you want to remove. If this argument is omitted, the default character to be removed is a blank. If you include a list of characters to remove, only those characters will be removed (unless the 'k' modifier is used). If a blank is not included in the list, blanks will not be removed

  modifiers is an optional list of modifiers that refer to character classes For example, the a modifier refers to all uppercase and lowercase characters. The following are some of the more useful modifiers: 




a     include all uppercase and lowercase letters.

d     include all digits

include all space characters (blanks, horizontal and vertical tabs, carriage return, linefeed, and formfeed).          

i    ignore the case of characters.

k   keep the characters listed in the compress-list or referenced by the modifiers instead of removing them.include all punctuation characters.referenced by the modifiers instead of removing them.

include all punctuation characters.         

Note that the modifiers can be in uppercase or lowercase.

If a length has not been previously assigned, the length of the resulting variable will be the length of the first argument.  



Example: Using the Compress function                                      
In the following examples, CHAR = "A C123XYZ".

Function                                                                    Returns
COMPRESS("A C XYZ")
COMPRESS("(908) 777-1234"," (-)")
COMPRESS(CHAR,,'as')
COMPRESS(CHAR,"0123456789")
COMPRESS(CHAR,,'d')
COMPRESS(CHAR,"ABC",'d')
COMPRESS(CHAR,,'kd')
"ACXYZ"
"9087771234"
"123"
"A CXYZ"
"A CXYZ"
" XYZ"
"123"
                                                                        








Comments

Popular posts from this blog

UPCASE, LOWCASE & PROPCASE

Function :MDY