请选择 进入手机版 | 继续访问电脑版
楼主: l1i2n3i4n5g
3764 4

[程序分享] 去除字符串头尾分号的三种方法 [推广有奖]

教授

25%

还不是VIP/贵宾

-

威望
0
论坛币
4501 个
通用积分
76.6084
学术水平
171 点
热心指数
204 点
信用等级
133 点
经验
24581 点
帖子
584
精华
1
在线时间
1862 小时
注册时间
2008-5-25
最后登录
2023-9-20

l1i2n3i4n5g 在职认证  发表于 2018-8-10 15:59:00 |显示全部楼层 |坛友微信交流群

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
/*去除字符串头尾分号的三种方法*/
data test;
   x=';;;中国;美国;日本;;;;;;';
   y1=Translate(strip(Translate(x,' ',';')),';',' ');   /*前提:字符串中不含空格*//*此法效率最高*/
   y2=substr(x,findc(x,';','k'),findc(x,';','bk')-findc(x,';','k')+1);
   y3=prxchange('s/^;*([^;].*[^;])(;+)?$/$1/o',1,x);
run;

二维码

扫码加我 拉你入群

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

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

关键词:效率最高 字符串

已有 2 人评分学术水平 热心指数 信用等级 收起 理由
eijuhz + 1 精彩帖子
whymath + 1 + 1 + 1 精彩帖子

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

hsubin 在职认证  发表于 2018-8-11 00:49:07 |显示全部楼层 |坛友微信交流群
学习了

使用道具

小明12345 发表于 2018-8-16 11:01:39 |显示全部楼层 |坛友微信交流群
学习了.

使用道具

albusdzx 发表于 2018-8-16 12:00:15 |显示全部楼层 |坛友微信交流群
螃蟹哥厉害 膜拜

使用道具

l1i2n3i4n5g 在职认证  发表于 2018-10-22 10:49:16 |显示全部楼层 |坛友微信交流群
data test;
   input id $ time $ rna $1.;
cards;
1 1 1
1 2 0
1 3 0
1 4 0
1 5 0
2 1 1
2 2 0
2 3 0
2 4 1
2 5 0
3 1 1
3 2 0
3 3 1
3 4 1
3 5 1
;
run;

data want;
   set test;
   by id;
   retain temp1;
   if first.id then do;
      call missing(temp1);
      call missing(temp2);
   end;
   if rna=0 then temp1=1;
   if temp1=1 then temp2+rna;
   if last.id then do;
      if rna=1 then type='c';
      else if temp2=0 then type='a';
      else if temp2>0 then type='b';
   end;
run;
proc print;
run;


data want;
   set test;
   by id;
   length temp1 $100;
   retain temp1;
   if first.id then call missing(temp1);
   temp1=cats(temp1,rna);
   if last.id then do;
      if prxmatch('/^1*0+\s*$/o',temp1) then type='a';
      if prxmatch('/^1*0[01]*1[01]*0\s*$/o',temp1) then type='b';
      if prxmatch('/^1*0[01]*1\s*$/o',temp1) then type='c';
   end;
run;
proc print;
run;

使用道具

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

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-3-29 20:59