SAS函数 – compress
分类:SAS
from (5)SAS函数 - compress_GoMine_新浪博客 (sina.com.cn)
COMPRESS 函数----从一个字符串移除特定的字符
COMPRESS (<source>,<chars>,<modifiers>)
source 指定一个要被移除字符的源字符串。
chars 指定一栏初始字符,默认它是要从source里移除的。
modifiers 指定一个修饰符,函数的具体功能。如:
a 增加(A - Z, a - z)到初始字符里(chars)。
d 增加数字到初始字符里(chars)。
f 增加下划线和字母 (A - Z, a - z) 到初始字符里(chars)。
g 增加图形字符到初始字符里(chars)。
k 不移除初始字符(chars)而是返回这些字符。
l 增加小写字母(a - z)。
n 增加数字、下划线和字母(A - Z, a - z)。
p 增加标点符号。
s 增加空格,包括空格,水平制表符,垂直制表符,回车符,换行符和换页符。
t 剪掉尾部空格。
u 增加大写字母(A - Z)。
w 增加可印刷的字符。
X 增加十六进制字符
1. 只有source,移除空格。
2. 只有source,chars时,从source中移除chars。
3. source ,chars,modifiers都有时,modifiers K决定保留还是移除。无K时,移除chars加上modifiers指定的。例如这两都是移除数字,COMPRESS(source, "1234567890");compress(source, , "d");这两个是移除数字和加减号,COMPRESS(source, "1234567890+-");COMPRESS(source, "+-", "d");Example 1:移除日期中的/。data _null_;
a='2010/11/19';;
b=compress(a,'/');
put b;
run;
结果是20101119。
Example 2:移除大写字母和-。data _null_;
x='123-4567-8901 B 234-5678-9012 c';
y=compress(x,'-','u');
put y;
run;
结果是12345678901 23456789012 c。
Example 3:移除Tabdata _null_;
x='1 2 3 4 5';
y=compress(x,,'s');
put y;
run;
结果是12345。
Example 4:移除Tabdata _null_;x='1 2 3 4 5';y=compress(x,' ');put y;run;结果是12345。
2. 只有source,chars时,从source中移除chars。
3. source ,chars,modifiers都有时,modifiers K决定保留还是移除。无K时,移除chars加上modifiers指定的。例如这两都是移除数字,COMPRESS(source, "1234567890");compress(source, , "d");这两个是移除数字和加减号,COMPRESS(source, "1234567890+-");COMPRESS(source, "+-", "d");Example 1:移除日期中的/。data _null_;
a='2010/11/19';;
b=compress(a,'/');
put b;
run;
结果是20101119。
Example 2:移除大写字母和-。data _null_;
x='123-4567-8901 B 234-5678-9012 c';
y=compress(x,'-','u');
put y;
run;
结果是12345678901 23456789012 c。
Example 3:移除Tabdata _null_;
x='1 2 3 4 5';
y=compress(x,,'s');
put y;
run;
结果是12345。
Example 4:移除Tabdata _null_;x='1 2 3 4 5';y=compress(x,' ');put y;run;结果是12345。