SAS:如何创建一个 table 列出另一个 table 的变量名称
SAS: How to create a table that lists the variable names of another table
我刚开始使用 SAS 和 PROC SQL,我想完成一个非常简单的任务,如下所述,但遇到了麻烦。
data test;
input x_ray y_chromosome z_sword;
cards;
1 2 3
4 5 6
4 7 8
7 8 9
7 9 10
7 10 11
;
在table测试中我们有三个变量,x_ray,y_chromosome,以及z_sword.
我的目标是制作另一个 table,比方说,结果,看起来像这样。
data result;
input name $;
cards;
x_ray
y_chromosome
z_sword
;
我在网上查了很多方法,但是所有的方法都超出了我的理解范围,我根本不相信这么简单的过程要这么复杂。
请问有什么帮助吗?
使用 PROC 内容。
proc contents data=test noprint out=result;
run;
如果您只需要变量名而不需要其他信息,您可以使用数据集选项来限制保留在 RESULT 数据集中的变量。
proc contents data=test noprint out=result(keep=name) ;
run;
我找不到比@Tom更短更简单的答案了,只是另外两种方式供参考。
使用字典 table:
proc sql;
create table result as select name from sashelp.vcolumn where libname='WORK' and memname='TEST';
quit;
或通过I/O函数查询:
data result;
rc = open('work.test');
if rc then do;
do i = 1 to attrn(rc,'nvars');
name = varname(rc,i);
output;
end;
rc = close(rc);
end;
run;
我刚开始使用 SAS 和 PROC SQL,我想完成一个非常简单的任务,如下所述,但遇到了麻烦。
data test;
input x_ray y_chromosome z_sword;
cards;
1 2 3
4 5 6
4 7 8
7 8 9
7 9 10
7 10 11
;
在table测试中我们有三个变量,x_ray,y_chromosome,以及z_sword.
我的目标是制作另一个 table,比方说,结果,看起来像这样。
data result;
input name $;
cards;
x_ray
y_chromosome
z_sword
;
我在网上查了很多方法,但是所有的方法都超出了我的理解范围,我根本不相信这么简单的过程要这么复杂。
请问有什么帮助吗?
使用 PROC 内容。
proc contents data=test noprint out=result;
run;
如果您只需要变量名而不需要其他信息,您可以使用数据集选项来限制保留在 RESULT 数据集中的变量。
proc contents data=test noprint out=result(keep=name) ;
run;
我找不到比@Tom更短更简单的答案了,只是另外两种方式供参考。
使用字典 table:
proc sql;
create table result as select name from sashelp.vcolumn where libname='WORK' and memname='TEST';
quit;
或通过I/O函数查询:
data result;
rc = open('work.test');
if rc then do;
do i = 1 to attrn(rc,'nvars');
name = varname(rc,i);
output;
end;
rc = close(rc);
end;
run;