bobguy 发表于 2011-3-20 10:06 
priss111 发表于 2011-3-19 17:27 
请问:如何提取字符型变量中的数字?
或者说对提取字符型变量的函数是哪个(V9.1)?
谢谢!
具体如下:
cardid是字符变量,其格式为:
'-148616'
'-148403'
'28110954'
'1000000000'
...
data card;
set card;
cardid=substr(card_id,3,length(card_id)-4);
run;
NOTE: 函数 SUBSTR 的第三参数(行 2495 列 4)无效。
...
SUBSTR Functiontakes substrings of matrix elements SUBSTR( matrix, position)
The inputs to the SUBSTR function are as follows:
matrix is a character matrix or quoted literal.
position is a numeric matrix or scalar giving the starting position.
length is a numeric matrix or scalar giving the length of the substring.
In a simple case as above, you may do as,
data w;
length x $50;
input x;
cards;
'-148616'
'-148403'
'28110954'
'1000000000'
;
data card;
set w;
*cardid=substr(card_id,3,length(card_id)-4);
y=input(compress(x,"'"), best.);
run;
proc print;run;
非常感谢!
这个数据是从csv数据库(里面很多汉字(字符变量))转化过了,而且观测有15万,变量80个以上。
在分析之前要预处理数据(以前从未接触过这么实际鲜活的数据),遇到很多问题,多谢指教!
card_id 变量的实际数据为:
‘-148616’
‘-1487177’
‘-28110954’
‘1000000000001256’
‘1000000000053126’
...
data card1;
set card;
cardid=input(compress(card_id," ‘’ "),best.);
run;
求职招聘 在线投稿
经管百科 三人行网
我也想创建词条赚积分
请问:如何提取字符型变量中的数字?
或者说对提取字符型变量的函数是哪个(V9.1)?
谢谢!
具体如下:
cardid是字符变量,其格式为:
'-148616'
'-148403'
'28110954'
'1000000000'
|
运行这段code后,card1中:当card_id=‘1000000000001256’时,cardid=1000000000001,凡card_Id的字符串超过12位后面的4位均读不出来;
然后将 input函数中的best.改为best20.,运行结果显示:当card_Id=‘1000000000001256’时,cardid=1E15用科学计算法显示了。
我只想将card_Id中左右两边的逗号去掉,cardid显示card_Id变量逗号中数字,这个数字不表示大小就表示一个匹配变量(因为csv数据库生成的就是这样一个变量)。
请再帮忙看看,这个怎么解决?谢谢!