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

怎么截取括号之前的字符? [推广有奖]

  • 0关注
  • 1粉丝

硕士生

87%

还不是VIP/贵宾

-

威望
0
论坛币
55 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
1889 点
帖子
126
精华
0
在线时间
225 小时
注册时间
2010-5-14
最后登录
2023-9-1

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
mayer(#qs)asceding(#qs)
如果有一列类似的变量,请问怎么样能截取每个变量值括号之前的字符建立新的变量?
比如
mayer
asceding?
非常感谢!
二维码

扫码加我 拉你入群

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

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

关键词:Mayer DING ASCE 非常感谢 SCE

不会

使用道具

wsddzr 发表于 2015-7-11 13:18:53 |显示全部楼层 |坛友微信交流群
只会一点点,希望能给你些灵感,你可以根据情况改进下
或者等大神来答~~
  1. data _null_;
  2. x='mayer(#qs)asceding(#qs)';
  3. y=scan(x,1,'()');
  4. put y;
  5. run;
复制代码

使用道具

苹果叶 在职认证  发表于 2015-7-11 20:48:56 |显示全部楼层 |坛友微信交流群
  1. data test;
  2.   a='mayer(#qs)asceding(#qs)test()new)(aaa(';
  3.   count=count(a,'(');
  4.   retain right 0;
  5.   do i=1 to lengthn(a);
  6.     if substr(a,i,1)=')' and i<lengthn(a) and substr(a,i,2) ne ')(' then do;
  7.             right=i;
  8.         end;
  9.     if substr(a,i,1)='(' and i>right+1 then do;
  10.                 current_i=i;
  11.                 last_i=coalesce(lag(current_i), 0);
  12.             col1=substr(a, max(last_i, right)+1,i-max(last_i, right)-1);
  13.                 output;
  14.         end;
  15.   end;
  16.   drop i right last_i current_i;
  17. run;
复制代码

我觉得因为一个字符串里面可能包含多个左括号,所以不能单纯用scan

使用道具

farmman60 发表于 2015-7-12 00:14:44 |显示全部楼层 |坛友微信交流群
  1. data test;
  2.   a='mayer(#qs)asceding(#qs)test()new)(aaa(';
  3.   b=prxchange('s/\(.*?\)|\(|\)/ /',-1,a);
  4.   do i=1 to countw(b,' ');
  5.      word=scan(b,i);
  6.          output;
  7.   end;
  8. drop a b;
  9. run;
复制代码

使用道具

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

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

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

GMT+8, 2024-4-19 01:27