COMPRESS: SAS Function strips characters from the string
Get link
Facebook
X
Pinterest
Email
Other Apps
-
In SAS 9.1.3 , an extra argument (MODIFIER) is added to the SAS character string function COMPRESS and these modifiers modifies the action of the COMPRESS function; Syntax: COMPRESS(<, chars><, modifiers>) ;
Following characters can be used as modifiers.
a – Compress or Delete all upper and lower case characters from String.
ak- Compress or Delete alphabetic characters(1,2,3 etc) from String.
kd- Compress or Delete characters(aplabets) from String.( Keeps only digits).
d – Compress or Delete numerical values from String.
i – Compress or Delete specified characters both upper and lower case from String.
k – keeps the specified characters in the string instead of removing them.
l – Compress or Delete lowercase characters from String.
p – Compress or Delete Punctuation characters from String.
s – Compress or delete spaces from String. This is default.
u – Compress or Delete uppercase characters from String. See the Example below:
data_null_ ;
string='StudySAS Blog! 17752. ' ; string1=compress(string,'') ; *Compress spaces. This is default; string2=compress(string,'','ak');*Compress alphabetic chars(1,2etc); string3=compress(string,'','d') ; *Compress numerical values; string4=compress(string,'','l');*Compress lowercase characters; string5=compress(string,'','u');*Compress uppercase characters; string6=compress(string,'S','k');*Keeps only specifiedcharacters; string7=compress(string,'!.','P');*Compress Punctuations only; string8=compress(string,'s','i');*upper/lower case specified characters; string9=compress(string,'','a');*Compress all upper\lower case characters ; string10=compress(string,'','s') ; * Compress or delete spaces; string11=compress(string,'','kd') ; *Compress alphabets (Keeps only digits); put string1= ; put string2= ; put string3= ; put string4= ; put string5= ; put string6= ; put string7= ; put string8= ; put string9= ; put string10=; put string11=; run ;
OUTPUT:
string1=StudySASBlog!17752.
string2=StudySAS Blog string3=StudySASBlog!. string4=SSASB!17752. string5=tudylog!17752. string6=SSS string7=StudySAS Blog 17752 string8=tudyA Blog! 17752. string9=!17752. string10=StudySASBlog!17752. string11=17752
Very nice
ReplyDeleteak- Compress or Delete alphabetic characters(1,2,3 etc) from String.
ReplyDeleteAND:
string2=compress(string,'','ak');*Compress alphabetic chars(1,2etc);
These two lines confused me. 1,2 etc are numeric characters, not alphabetic characters.
Clearest explanations I've seen on compress.
ReplyDelete