楼主: priss111
10156 5

[原创博文] 请教:如何提取字符型变量里的字符串? [推广有奖]

  • 0关注
  • 5粉丝

已卖:9份资源

副教授

16%

还不是VIP/贵宾

-

威望
0
论坛币
153 个
通用积分
47.5396
学术水平
11 点
热心指数
14 点
信用等级
10 点
经验
14935 点
帖子
472
精华
0
在线时间
808 小时
注册时间
2008-3-30
最后登录
2025-3-17

楼主
priss111 发表于 2011-3-19 17:27:53 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
请问:如何提取字符型变量中的数字?
或者说对提取字符型变量的函数是哪个(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.
二维码

扫码加我 拉你入群

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

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

关键词:字符型变量 如何提取 字符串 字符型 substring

回帖推荐

bobguy 发表于2楼  查看完整内容

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;

本帖被以下文库推荐

沙发
bobguy 发表于 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;
已有 1 人评分经验 论坛币 收起 理由
bakoll + 3 + 3 精彩帖子

总评分: 经验 + 3  论坛币 + 3   查看全部评分

藤椅
priss111 发表于 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数据库生成的就是这样一个变量)。

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

板凳
bobguy 发表于 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;
已有 1 人评分学术水平 热心指数 收起 理由
priss111 + 1 + 1 非常感谢,学习了。

总评分: 学术水平 + 1  热心指数 + 1   查看全部评分

报纸
priss111 发表于 2011-3-21 08:23:54
4# bobguy

非常感谢!!学习中。

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

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

地板
leedx 发表于 2011-3-21 10:04:10
学习中~

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-30 06:41