SAS中文论坛

标题: 急问如何在sas中进行变量的批量重命名? [打印本页]

作者: shiyiming    时间: 2005-10-25 11:27
标题: 急问如何在sas中进行变量的批量重命名?
假设有一组变量a b c,想在这些变量的前面都加上一个相同的字符串,如变成d_a,d_b,d_c,应该如何编程啊?
作者: shiyiming    时间: 2005-11-11 00:18
标题: Re:
data a;input a b c@@;cards;
1 2 3 ……
;run;
data b;set a(rename=(a=d_a b=d_b c=d_c));run;
作者: shiyiming    时间: 2005-11-17 09:09
标题: better solution
data one;
input a b c d e f g h i j;
cards;
1 2 3 4 5 6 7 8 9 10
;
run;

ods listing close;
ods output position = list;
proc contents data = one varnum;
run;
ods listing;

proc sql noprint;
select put(max(num), 2.) into :num from list;
select variable into :var1-:var&num from list;
select "rename_"||variable into :new1-:new&num from list;
quit;

%macro rename;

%do i = 1 %to &num.;
&&var&i = &&new&i.
%end;

%mend rename;

proc datasets lib = work;
modify one;
rename %rename;
run;
quit;
作者: shiyiming    时间: 2005-11-23 20:55
标题: aother solution!
data one;
label a='d_a' b='d_b' c='d_c';
input a b c @@;
cards;
1 2 3
3 2 4
4 7 9
;
proc print label;
run;
作者: shiyiming    时间: 2005-11-23 21:46
标题: to homestay
do you understand the question?
作者: shiyiming    时间: 2005-11-24 10:27
标题: to winslow
[code:e3044]
data one;
input a b c d e f g h i j;
cards;
1 2 3 4 5 6 7 8 9 10
;
run;

ods output position = list(keep=variable);
proc contents data = one;
run;

filename test "C:\test.sas";
data _null_;
file test;
set list;
put 'd_' variable;
run;[/code:e3044]
作者: shiyiming    时间: 2005-11-24 14:58
标题: I think wislow's is more powful.
I think wislow's is more powful.
作者: shiyiming    时间: 2005-12-7 10:55
标题: 使用PROC SQL
[code:92b5e]
假设你要重新命名字段的数据表为WORK.TEST,需要添加的前缀为"d_",代码为:
PROC SQL NOPRINT;
      SELECT TRIM(NAME)||"=d_"||TRIM(NAME)  INTO :STR_RENAME SEPARATED BY ' '
            FROM SASHELP.VCOLUMN
            WHERE LIBNAME="WORK" AND MEMNAME="TEST";
QUIT;
DATA WORK.TEST;
      SET WORK.TEST;
      RENAME &STR_RENAME;
RUN;
[/code:92b5e]
作者: shiyiming    时间: 2006-8-28 12:29
标题: Re
各位的想法都是很好的,其中winslow的程序在sas9.0中如果不做任何改动的话,改名成功,但如果换一个数据集的话就不行了,collon的程序则只能改变变量名,而不能和原先的数据集联系起来,请各位费心做进一步的指导,谢谢!
作者: shiyiming    时间: 2006-8-28 21:57
标题: to wmqy2004
楼上的是赵本山?
作者: shiyiming    时间: 2006-10-8 13:20
标题: to ahuige
我不明白你老兄的意思,说实话,我无意于诋毁任何人,只是想在与各位交流中多学到一些知识而已。

我对楼主提出的这个问题比较感兴趣,而且自己在实际工作中也遇到了类似的问题,因此,我将上述各位的方案均在sas9.0中一一进行了验证,结果确实未能实现预期的目的。
作者: shiyiming    时间: 2008-11-25 16:56
标题: Re: 急问如何在sas中进行变量的批量重命名?
一些处理都不错。。。
作者: shiyiming    时间: 2008-11-25 18:17
标题: Re: 急问如何在sas中进行变量的批量重命名?
试了collen的程序,觉得是否要修改下呢?
data one;
input a b c d e f g h i j;
cards;
1 2 3 4 5 6 7 8 9 10
;
run;
ods output variables=two(keep=variable);
proc contents data = one;
run;
ods output close;
filename test "e:\test.txt";
data _null_;
file test;
set two;
put 'd_'variable;
run;
我试了报错 <!-- s:D --><img src="{SMILIES_PATH}/icon_biggrin.gif" alt=":D" title="Very Happy" /><!-- s:D -->




欢迎光临 SAS中文论坛 (https://mysas.net/forum/) Powered by Discuz! X3.2