SAS中文论坛

标题: 如何取字段中的数字? [打印本页]

作者: shiyiming    时间: 2006-3-28 07:10
标题: 如何取字段中的数字?
data test;
input char $;
datalines;
abcde
123
34343abc
as343
as  34
;
run;

.
123
34343
343
34

?谢谢先。用index, 和compress都不成功。
作者: shiyiming    时间: 2006-3-28 12:45
标题: to oooh
[code:497f0]number=compress(string, compress(string, '0123456789'));[/code:497f0]
也就是去除0-9之外其他所有字符。不过有个问题我还是没有解决,就是如果字符串是'12ab34',这样的逻辑就成了'1234'。这种情况还想不出怎么办好。
作者: shiyiming    时间: 2006-3-28 21:06
标题: zz
number=compress(string, compress(string, '0123456789.'));

就可以读取小数了。

12ab34 确实逻辑上不对。。。 再谢谢啦 <!-- s:lol: --><img src="{SMILIES_PATH}/icon_lol.gif" alt=":lol:" title="Laughing" /><!-- s:lol: -->
作者: shiyiming    时间: 2006-3-29 15:40
标题: 呵呵
还是用正则表达式才是正道啊
作者: shiyiming    时间: 2006-3-30 09:26
标题: to ahuige
简单的还行,但每次看到复杂的正则表达式的语法都犯憷。还是不太熟,用的少的缘故。
以后向你请教正则表达式。 <!-- s:oops: --><img src="{SMILIES_PATH}/icon_redface.gif" alt=":oops:" title="Embarassed" /><!-- s:oops: -->
作者: shiyiming    时间: 2006-4-7 14:47
标题: TO oooh
data test;
length char $ 50;
input char $;
datalines;
abcde
123
34343abc
as343
as34
12ab34
1a3b4c5d2
11.25x26c37.001v
;
run;

data test;
set test;
no+1;
run;

data a;
set test;
length ch2 $50;
ch2='';
do i=1 to length(compress(char));
   ch1=substr(char,i,1);
   if ch1*1&lt;0 and compress(ch1)^='.' then do;
      ch1='-';
   end;
   ch2=compress(ch2)||put(ch1,1.0);
   output;
end;
drop i;
run;

proc sort data=a;
by no;
run;

data a;
set a;
by no;
if last.no;
run;

data a2;
set a;
j=length(compress(ch2))-length(compress(ch2,'-'));
run;

proc sql;
create table a3 as select max(j) as n from a2;
run;

data a3;
set a3;
call symput('max',n);
run;

%macro char(i);
data a4;
set a2;
do &amp;i=1 to &amp;max;
   char1=scan(ch2,&amp;i,'-');
   output;
end;
run;

data a4;
set a4;
if compress(char1)='' then delete;
keep no char char1;
run;

data test;
merge test a4;
by no;
drop no;
run;
%mend;

%char(i);
作者: shiyiming    时间: 2006-4-20 06:46
标题: 想法
我的想法;用一个函数来截取值的每个字符,然后用ASCII码来判断,然后再输出,这个应该可以写成一个标准函数,就像sas的函数一样的




欢迎光临 SAS中文论坛 (http://mysas.net/forum/) Powered by Discuz! X3.2