Hi,
I have a library of 100+ datasets each with 10+variables. I was wondering if it was possible to output an excel table that had the table name and the column names to the right kind of like the format below.
Dataset_name1 | variable_1 | variable_2
dataset_name2 | variable_1 | variable_2| ....
Any help would be greatly appreciated.
Thank you.
Check out sashelp.vcolumn and sashelp.vtable views in the sashelp library.
That was helpful @Reeza !
Thank you.
- Dr. Abhijeet Safai
@DrAbhijeetSafai Just adding the bit of code required to store the result in a Excel sheet. Else just using Tom's code so suggest you accept his proposal as solution.
options dlcreatedir;
libname mylib "%sysfunc(pathname(work))\source";
data mylib.class;
set sashelp.class;
run;
data mylib.air;
set sashelp.air;
run;
proc contents data=mylib._all_ noprint out=contents;
run;
proc sort data=contents;
by libname memname varnum ;
run;
libname exl xlsx "%sysfunc(pathname(work))\myexcle.xlsx";
proc transpose data=contents out=exl.wide(drop=_name_ _label_) prefix=var;
by libname memname ;
id varnum;
var name;
run;
Something like this perhaps? You would specify your library name instead of WORK and the name stored is in uppercase so provide it that way.
proc transpose data=sashelp.vcolumn out= trans (drop=_name_ _label_) prefix=Varname; where libname='WORK'; by memname; var name; run; proc print data=trans; run;
Depending on the purpose of this exercise there are other ways to use the Vcolumn data.
For example this creates a table that checks if the variables of the same name are of the same type
proc tabulate data=sashelp.vcolumn; where libname='WORK'; class memname name type; table name*type, memname*n=' ' /misstext=' ' ; run;
The columns are the data sets a 1 indicates that the variable name and type on the left of the row is in the data set.
If you have two types for the same variable they would be next to each other in rows to see which is where.
The n =' ' suppresses the column label of N. The Misstex=' ' table option displays no text instead of the default . for all the missing counts (variables not in the given data set column)
That is what PROC CONTENTS is for.
proc contents data=mylib._all_ noprint out=contents; run;
What do you want to DO with the list? if you would like it to appear in that strange wide format then transpose the data.
proc sort data=contents; by libname memname varnum ; run; proc transpose data=contents out=wide(drop=_name_ _label_) prefix=var; by libname memname ; id varnum; var name; run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.