楼主: 乾坤神龙
3417 20

关于字符提取 [推广有奖]

11
tj0412ymy 发表于 2012-5-22 12:00:31
乾坤神龙 发表于 2012-5-22 10:57
这位老大,非常感谢你的帮助;
对于C=TRANSLATE(B,'',A);
这个作用机制还是有点不明白,希望得到您的指 ...
Translate是替换字符串函数,将A在B中的部分替换为''。
对SAS和统计方面感兴趣的朋友,请加SAS学习和认证讨论群:169157207。欢迎在群上讨论!

12
乾坤神龙 发表于 2012-5-22 13:05:30
tj0412ymy 发表于 2012-5-22 12:00
Translate是替换字符串函数,将A在B中的部分替换为''。
感谢您的指导!!

13
chendonghui1987 发表于 2012-5-22 15:28:33
TRANSLATE(source,to-1,from-1 <,...to-n,from-n>)  



source
specifies the SAS expression that contains the original character value.

to
specifies the characters that you want TRANSLATE to use as substitutes.

from
specifies the characters that you want TRANSLATE to replace.

14
乾坤神龙 发表于 2012-5-22 15:29:13
chendonghui1987 发表于 2012-5-22 15:28
TRANSLATE(source,to-1,from-1 )
感谢感谢!!

15
sunset1986 发表于 2012-5-22 17:29:00
data b (drop=C);
set a;
C=TRANSLATE(B,'',A);
D=compress(C,' ', 's');
run;

这样可以让你的变量少一些空格的干扰,呵呵
An honest tale speeds best being plainly told.
Cheers!

16
sunset1986 发表于 2012-5-22 17:32:18
data c;
        set a;
        C=substr(B, length(A)+1,(Length(B)-Length(A)));
run;

或者这样,也可以省去空格之苦,哈哈
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
乾坤神龙 + 1 + 1 + 1 观点有启发

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

An honest tale speeds best being plainly told.
Cheers!

17
乾坤神龙 发表于 2012-5-23 09:47:30
sunset1986 发表于 2012-5-22 17:32
data c;
        set a;
        C=substr(B, length(A)+1,(Length(B)-Length(A)));
感谢感谢,两种方法都很好!!

18
sunset1986 发表于 2012-5-23 09:56:54
乾坤神龙 发表于 2012-5-23 09:47
感谢感谢,两种方法都很好!!
客气咯~
An honest tale speeds best being plainly told.
Cheers!

19
龙潭丰乐 学生认证  发表于 2012-11-15 18:39:22
tj0412ymy 发表于 2012-5-21 19:13
请教老师  x_sub=substr(x,length(x)-4,5)意思是从第十六个字符开始提取5个?

20
lily83322 发表于 2012-11-16 14:33:16
compress一下

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-1 20:57