m******m 发帖数: 445 | 1 I have a char variable in a large dataset, containing different type of
characters. I want to keep only alphabet and number in this variable. At
first I want to use compress function but the point is that I don't know all
the other character in the variable. I can check several observations and
get some of them but don't know how to do a thorough test to get all of them
.
Is there anyway to do it in SAS? thanks! | p********a 发帖数: 5352 | 2 data a;
b='sada9>a876&&*gh##98';
output;
b='sada<9>a876&*gh##98';
output;
run;
data c;
length b1 $20.;
set a;
b1='';
do i=1 to length(b);
if anyalnum(b,i)=i then b1=cats(b1,substr(b,i,1));
end;
drop b i;
run;
proc print;run; | t*a 发帖数: 117 | 3 if you have 9.1, you can use COMPRESS function with modifiers.
in your case, you can simply use:
new =compress(old,,'adk'); /* A for letters (upper and lower),
D for numbers,
K for keep)*/
http://support.sas.com/onlinedoc/913/getDoc/en/lrdict.hlp/a000212246.htm
all
them
【在 m******m 的大作中提到】![](/moin_static193/solenoid/img/up.png) : I have a char variable in a large dataset, containing different type of : characters. I want to keep only alphabet and number in this variable. At : first I want to use compress function but the point is that I don't know all : the other character in the variable. I can check several observations and : get some of them but don't know how to do a thorough test to get all of them : . : Is there anyway to do it in SAS? thanks!
| m******m 发帖数: 445 | 4 Yes I just figure out this. I use 9.1.3 but I always use v8 online help.
That's why I couldn't find this new modifier. Thanks!
【在 t*a 的大作中提到】![](/moin_static193/solenoid/img/up.png) : if you have 9.1, you can use COMPRESS function with modifiers. : in your case, you can simply use: : new =compress(old,,'adk'); /* A for letters (upper and lower), : D for numbers, : K for keep)*/ : http://support.sas.com/onlinedoc/913/getDoc/en/lrdict.hlp/a000212246.htm : : all : them
| m******m 发帖数: 445 | 5 thanks! good to learn some new functions.
【在 p********a 的大作中提到】![](/moin_static193/solenoid/img/up.png) : data a; : b='sada9>a876&&*gh##98'; : output; : b='sada<9>a876&*gh##98'; : output; : run; : data c; : length b1 $20.; : set a; : b1='';
|
|