楼主: dxystata
5401 5

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

版主

已卖:302份资源

大师

37%

还不是VIP/贵宾

-

TA的文库  其他...

Software

中英文Ebook

R学习

威望
2
论坛币
183395 个
通用积分
15333.1475
学术水平
208 点
热心指数
271 点
信用等级
174 点
经验
298627 点
帖子
5586
精华
1
在线时间
13632 小时
注册时间
2006-6-21
最后登录
2025-12-2

初级学术勋章 初级热心勋章 中级热心勋章 初级信用勋章

楼主
dxystata 发表于 2014-11-23 09:43:21 |AI写论文
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
拉您进交流群
GMT+8, 2025-12-9 06:52