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

如何用宏实现对数据集aaa中的变量标签进行修改 [推广有奖]

版主

大师

34%

还不是VIP/贵宾

-

TA的文库  其他...

Software

中英文Ebook

R学习

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

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

dxystata 发表于 2014-11-23 09:37:40 |显示全部楼层 |坛友微信交流群
100论坛币
  1. data aaa;
  2. input no age sex height0 weight0 weight1;
  3. label age='年龄' height0='身高' weight0='体重' weight1='体重';
  4. cards;
  5. 1 35 1 175 80 90
  6. 2 45 2 160 55 65
  7. ;
  8. run;

  9. data bbb;
  10. input name$ label$;
  11. cards;
  12. age 年龄(岁)
  13. height 身高(cm)
  14. weight 体重(kg)
  15. ;
  16. run;
复制代码
根据数据集bbb,如何用宏实现对数据集aaa中的变量标签进行修改?就是
age的标签为年龄(岁)
height0的标签为身高(cm)
weight0的标签为体重(kg)
weight0的标签为体重(kg)

注:数据集aaa中height0 weight0 weight1 后面的数字去掉后和数据集bbb中的name的值对应


最佳答案

pobel 查看完整内容

proc sql noprint; select catx("=",a.name,quote(strip(b.label))) into :setlabel separated by " " from (select distinct name from dictionary.columns where libname="WORK" and memname="AAA") as a inner join bbb as b on a.name eqt b.name; quit; proc datasets lib=work; modify aaa; label &setlabel; run;quit;
关键词:如何用 数据集 Weight Eight weigh 标签 如何

本帖被以下文库推荐

pobel 在职认证  发表于 2014-11-23 09:37:41 |显示全部楼层 |坛友微信交流群
proc sql noprint;
   select catx("=",a.name,quote(strip(b.label))) into :setlabel separated by " "
   from (select distinct name from  dictionary.columns where libname="WORK" and memname="AAA") as a
       inner join bbb as b
            on a.name eqt b.name;
quit;

proc datasets lib=work;
   modify aaa;
   label &setlabel;
run;quit;
已有 1 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
Tigflanker + 5 + 3 + 3 + 3 观点有启发

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

使用道具

luoguifa 发表于 2014-11-23 10:13:29 |显示全部楼层 |坛友微信交流群
求解答

使用道具

farmman60 发表于 2014-11-24 01:47:24 |显示全部楼层 |坛友微信交流群
  1. data aaa;
  2. input no age sex height0 weight0 weight1;
  3. label age='Age' height0='Height' weight0='Weight' weight1='Weigth';
  4. cards;
  5. 1 35 1 175 80 90
  6. 2 45 2 160 55 65
  7. ;
  8. run;

  9. proc contents data=aaa;

  10. data bbb;
  11. name='age    '; label='Age(yrs)      ';
  12. output;
  13. name='height'; label='Height(cm)';
  14. output;
  15. name='weight' ;label='Weight(kg)';
  16. output;
  17. run;

  18. data _null_;
  19.   if 0 then set bbb;
  20.   if _n_=1 then do;
  21.      declare hash h(dataset:'bbb');
  22.          declare hiter hi('h');
  23.          h.definekey('name');
  24.          h.definedata(all:'y');
  25.          h.definedone();
  26.          call execute ('proc datasets lib=work noprint;
  27.                        modify aaa;
  28.                                    label');
  29.   end;
  30.   set sashelp.vcolumn(where=(libname='WORK' and memname='AAA') rename=(name=temp) ) end=last;
  31.   _temp=compress(temp,,'ka');
  32.   rc=hi.first();
  33.   do while (rc=0);
  34.     rc1=h.find(key:_temp);
  35.         if rc1=0 then do;
  36.           call execute(temp||'='||label);
  37.    leave;
  38.          end;
  39.         else rc=hi.next();
  40.   end;
  41.   if last then call execute('; run;');
  42.   run;

  43.   proc contents data=aaa;
  44.   run;
复制代码

使用道具

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

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

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

GMT+8, 2024-3-29 07:34