请选择 进入手机版 | 继续访问电脑版
楼主: dxystata
4844 5

如何将变量标签中的括号和括号中内容去掉 [推广有奖]

版主

大师

34%

还不是VIP/贵宾

-

TA的文库  其他...

Software

中英文Ebook

R学习

威望
2
论坛币
181713 个
通用积分
15202.5562
学术水平
208 点
热心指数
271 点
信用等级
174 点
经验
289859 点
帖子
5347
精华
1
在线时间
13446 小时
注册时间
2006-6-21
最后登录
2024-3-29

初级学术勋章 初级热心勋章

dxystata 发表于 2014-11-23 09:43:21 |显示全部楼层 |坛友微信交流群
50论坛币
  1. data aaa;
  2. input no age sex height0 weight0 weight1;
  3. label age='年龄(岁)' height0='身高(cm)' weight0='体重(kg)' weight1='体重(kg)';
  4. cards;
  5. 1 35 1 175 80 90
  6. 2 45 2 160 55 65
  7. ;
  8. run;
复制代码
如何将数据集aaa中含有括号的变量标签中将括号和括号中内容去掉?谢谢!

最佳答案

pobel 查看完整内容

data _null_; set sashelp.vcolumn end=last; where libname="WORK" and memname="AAA" and index(label,"("); do until(index(label,"(")=0); if label =:"(" then label=substr(label,index(label,")")+1); else label=substr(label,1, index(label,"(")-1)|| substr(label,index(label,")")+1); end; length setlabel $100; setlabel=catx(" ",setlabel, catx("=",name,quote(strip(label)))); ...
关键词:Weight Eight weigh Input cards 饮水机 标签 如何

本帖被以下文库推荐

pobel 在职认证  发表于 2014-11-23 09:43:22 |显示全部楼层 |坛友微信交流群
data _null_;
    set sashelp.vcolumn end=last;
        where libname="WORK" and memname="AAA" and index(label,"(");
        do until(index(label,"(")=0);
           if label =:"(" then label=substr(label,index(label,")")+1);
       else label=substr(label,1, index(label,"(")-1)|| substr(label,index(label,")")+1);
        end;

        length setlabel $100;
        setlabel=catx(" ",setlabel, catx("=",name,quote(strip(label))));
        retain setlabel;
        if last then call symputx("setlabel",setlabel);
run;

proc datasets lib=work;
   modify aaa;
   label &setlabel;
run;quit;
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
Eternal0601 + 3 + 3 + 3 精彩帖子

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

使用道具

dxystata 发表于 2014-11-23 19:31:02 |显示全部楼层 |坛友微信交流群
pobel 发表于 2014-11-23 10:53
data _null_;
    set sashelp.vcolumn end=last;
        where libname="WORK" and memname="AAA" and index(l ...
:"("  表示什么意思?谢谢!
如果括号就有中文状态的括号和英文状态的括号呢?

使用道具

pobel 在职认证  发表于 2014-11-23 20:13:22 |显示全部楼层 |坛友微信交流群
dxystata 发表于 2014-11-23 19:31
:"("  表示什么意思?谢谢!
如果括号就有中文状态的括号和英文状态的括号呢?
=: 相当于sql中用的 eqt。

In a truncated string comparison, the comparison is performed after making the strings the same length by truncating the longer string to be the same length as the shorter string. For example, the expression 'TWOSTORY' eqt 'TWO' is true because the string 'TWOSTORY' is reduced to 'TWO' before the comparison is performed.

使用道具

farmman60 发表于 2014-11-24 06:13:17 |显示全部楼层 |坛友微信交流群
  1. data _null_;
  2.   set sashelp.vcolumn(where=(libname="WORK" and memname="AAA")) end=last;
  3.   if _n_=1 then call execute('
  4.          proc datasets lib=work;
  5.                  modify aaa;
  6.                  label');
  7.   pid=prxparse('s/\(.*\)//');
  8.   if prxmatch("/\(.*\)/",label)>0 then call prxchange(pid,-1,label);
  9.   call execute (name||'='||label);
  10.   if last then call execute(';run;');
  11.   run;
复制代码

使用道具

wh7064rg 发表于 2014-11-25 04:24:19 |显示全部楼层 |坛友微信交流群
学习了

使用道具

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

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

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

GMT+8, 2024-3-30 00:00