全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
10070 5
2011-03-19
请问:如何提取字符型变量中的数字?
或者说对提取字符型变量的函数是哪个(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<, length>)
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.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2011-3-20 10:06:14
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;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2011-3-20 14:26:28
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数据库生成的就是这样一个变量)。

请再帮忙看看,这个怎么解决?谢谢!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2011-3-21 03:11:52
priss111 发表于 2011-3-20 14:26
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数据库生成的就是这样一个变量)。

请再帮忙看看,这个怎么解决?谢谢!
If the maximum length is 30 for example and each number is an integer, you can use 30. informat to replace the best. informat. See below.

data w;
length x $50;
input x;
cards;
'1000000000001256'
;
data card;
set w;
*cardid=substr(card_id,3,length(card_id)-4);
y=input(compress(x,"'"), 30.);
run;

proc print data=card;
var y ;
run;

proc print data=card;
var y ;
format y 30.;
run;

proc print data=card;
var y ;
format y 30.5;
run;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2011-3-21 08:23:54
4# bobguy

非常感谢!!学习中。

运行下面code,也把中间的字符串提取出来了,主要是这个数据太庞杂了,汉字太多。

data  card1;
set card;
cardid=input(compress(card_id, " ‘’ "), $20.);
run;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2011-3-21 10:04:10
学习中~
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群