Reputation: 237
I am starting out with SAS and PROC SQL, and I want to do a very simple task as described below but am having trouble.
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
;
In the table test we have three variables, x_ray, y_chromosome, and z_sword.
My goal is to make another table, let's say, result, that looks like this.
data result;
input name $;
cards;
x_ray
y_chromosome
z_sword
;
I looked up ways to do this online, but all the methods are very well beyond my understanding and I simply do not believe that such a simple process has to be so complicated.
May I have some help, please?
Upvotes: 0
Views: 1747
Reputation: 1394
I cannot find any shorter and simpler answer than @Tom, just another two ways for reference.
Use dictionary table:
proc sql;
create table result as select name from sashelp.vcolumn where libname='WORK' and memname='TEST';
quit;
or query them by I/O functions:
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;
Upvotes: 0
Reputation: 51621
Use PROC CONTENTS.
proc contents data=test noprint out=result;
run;
If you only want the variable names and not the other information you can use dataset option to limit the variables kept in the RESULT dataset.
proc contents data=test noprint out=result(keep=name) ;
run;
Upvotes: 3