由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - SAS how to change variables' name
相关主题
ask for help (urgent): A SAS question请教一个SAS recode variable的问题吧
求教proc sql 问题SAS -proc transpose 急问!
再来请教,在SAS中如何得到下面的结果?sas大牛们这个要怎么实现呀
SAS code求教请问SPSS 或者 SAS中变量名的变换 AABB - BBAA
SAS 转 ExcelSAS问题请教
请教SAS 问题请教SAS LABEL问题。
请教:三道SAS BASE题SAS question - baozi
SAS中如何只保留变量名中含有reading的变量啊ask for help (urgent): A SAS question
相关话题的讨论汇总
话题: sas话题: variables话题: name话题: 30话题: lib
进入Statistics版参与讨论
1 (共1页)
m****r
发帖数: 202
1
I have to create a new SAS data set, and all variables in the new one should
be added _30 according to the old one. My plan is using the old one to
export .cvs first, in the .cvs replace original variables to original_30.
Then import .cvs to SAS data set.
Could anyone suggest a easier method to finish this job?
Many thanks
c*****t
发帖数: 1712
2
可以用proc transpose
m****r
发帖数: 202
3
Thanks. Could you please give me more detail?
My variable names are AS01d,AS01m,AS01y,AS02a,AS02b,AS02c,AS02_age.
I transposed them to observations, but still don't know how to add "_30" to
them.
Thanks a lot
R*********i
发帖数: 7643
4
After transposing the var names are changed to values in a new var (_name_),
you can add _30 at the end of the new var, e.g. name1=compress(_name_)||'_
30'. And then transpose back to the original structure using name1 as the ID
var.
R*********i
发帖数: 7643
5
If you only have that limited number of variables as listed above you may
want to use "rename" directly.
m****r
发帖数: 202
6
proc contents data=old
out=try(keep=varnum name)
noprint;
run;
data new (keep=newname varnum);
set try;
do i=1 to 1500;
if varnum=(i)
then newname=compress(name)||"_30";
end;
run;
proc transpose data=new
out=aa30d(drop=i _name_);
id newname;
run;
The problem here is some original cha variables have been changed to num
ones. This is not exactly I expect.
A*******s
发帖数: 3942
7
%macro add_prefix(lib=, table=, prefix=);
proc sql noprint;
select cats(name, '=', substr(cats(upcase("&prefix"), "_", name), 1, 32)
) into: rename_list separated by " "
from dictionary.columns
where libname=upcase("&lib") and memname=upcase("&table")
;
quit;
data &lib..prfx_&table;
set &lib..&table;
rename &rename_list ;
run;
%mend;

【在 m****r 的大作中提到】
: proc contents data=old
: out=try(keep=varnum name)
: noprint;
: run;
: data new (keep=newname varnum);
: set try;
: do i=1 to 1500;
: if varnum=(i)
: then newname=compress(name)||"_30";
: end;

m****r
发帖数: 202
8
Dear Actuaries,
Thanks a lot for you programming my question.
I need suffix,but this program gives me prefix.
original
AS01d,AS01m,AS01y,AS02a,AS02b,AS02c,AS02_age.
expected AS01d_30,AS01m_30,AS01y_30,AS02a_30,AS02b_30,AS02c_30,AS02_age_30
.
m****r
发帖数: 202
9
%macro add_suffix(lib=, table=, suffix=);
proc sql noprint;
select cats(name, '=',name, "_", substr(cats(upcase("&suffix")), 1, 32)
) into: rename_list separated by " "
from dictionary.columns
where libname=upcase("&lib") and memname=upcase("&table")
;
quit;
data &lib..prfx_&table;
set &lib..&table;
rename &rename_list ;
run;
%mend;
It gives me what I expect. Thanks all.
n*****n
发帖数: 3123
10
ft. 敢情你是什么都不会啊

30

【在 m****r 的大作中提到】
: Dear Actuaries,
: Thanks a lot for you programming my question.
: I need suffix,but this program gives me prefix.
: original
: AS01d,AS01m,AS01y,AS02a,AS02b,AS02c,AS02_age.
: expected AS01d_30,AS01m_30,AS01y_30,AS02a_30,AS02b_30,AS02c_30,AS02_age_30
: .

A*******s
发帖数: 3942
11
u need to understand why and how to use substr function to truncate the
variable names--to control the length up to 32 characters.

32)

【在 m****r 的大作中提到】
: %macro add_suffix(lib=, table=, suffix=);
: proc sql noprint;
: select cats(name, '=',name, "_", substr(cats(upcase("&suffix")), 1, 32)
: ) into: rename_list separated by " "
: from dictionary.columns
: where libname=upcase("&lib") and memname=upcase("&table")
: ;
: quit;
: data &lib..prfx_&table;
: set &lib..&table;

1 (共1页)
进入Statistics版参与讨论
相关主题
ask for help (urgent): A SAS questionSAS 转 Excel
问一个SAS format的问题,看似简单请教SAS 问题
请教如何用SAS处理这个RANDOM SAMPLING的问题请教:三道SAS BASE题
求高人指点一个SAS数据的转换问题SAS中如何只保留变量名中含有reading的变量啊
ask for help (urgent): A SAS question请教一个SAS recode variable的问题吧
求教proc sql 问题SAS -proc transpose 急问!
再来请教,在SAS中如何得到下面的结果?sas大牛们这个要怎么实现呀
SAS code求教请问SPSS 或者 SAS中变量名的变换 AABB - BBAA
相关话题的讨论汇总
话题: sas话题: variables话题: name话题: 30话题: lib