Reputation: 167
I'm trying to make a program to give me assignments to practice with for my SAS exam; I want to list the variables in all datasets as well as the type of variable;
libname printlib '...';
libname proclib '...';
proc datasets library=proclib memtype=data nolist;
copy out=printlib;
select delay internat;
run;
%macro printall(libname, worklib=work);
%local num i;
proc datasets library=&libname memtype=data nodetails;
contents out=&worklib..temp1(keep=memname) data=_all_ noprint;
run;
data _null_;
set &worklib..temp1 end=final;
by memname notsorted;
if last.memname;
n+1;
call symput('ds'||left(put(n, 8.)), trim(memname));
if final then
call symput('num', put(n, 8.));
run;
%do i=1 %to #
data work.data;
set &libname..&&ds&i;
var_type=vtype(name);
run;
proc contents data=work.data noprint out=data_info (keep=name varnum var_type);
run;
proc sort data=data_info out=variable_names(keep=name var_type);
by varnum;
run;
proc print data=work.variable_names;
title &libname..&&ds&i;
run;
%end;
%mend printall;
options nodate pageno=1 linesize=70 pagesize=60;
%printall(printlib)
The results should show the title which is the dataset name, the first column should be the variable name, and the second column should be the variable type (character or numeric)
Right now it's showing the title, and the variable names; but not the variable type. I'm not quite sure as to how to get the variable type to show up next to the variable name.
Upvotes: 0
Views: 1391
Reputation: 27508
Studying ? You need to deeply grok @Tom answer. The output can be cleaned up some, using a format to confer human readable type values, and the by variable values can be made to appear in a title statement using the #BYVALn
construct.
proc datasets noprint lib=work kill;
run;
data work.one(label="One is the loneliest number") work.two work.three;
set sashelp.cars(obs=1);
run;
proc contents noprint data=work._all_ out=contents;
run;
proc format;
value type 1='Num' 2='Char';
run;
proc sort data=contents;
by libname memname varnum;
options nobyline;
title "Dataset: #byval1..#byval2 (#byval3)";
proc print noobs label data=contents;
by libname memname memlabel;
var varnum name type label;
format type type.;
run;
title;
Upvotes: 0
Reputation: 3315
you can also use dictionary.columns. this gives tablename columnname and datatype
proc sql;
create table want as
select cats( libname,'.', memname) as tablename, name, type from
dictionary.columns;
Upvotes: 1
Reputation: 51566
Why are you making it so complicated?
proc contents data=&libname.._all_ noprint out=contents ;
run;
proc sort data=contents;
by memname varnum;
run;
proc print data=contents ;
by memname memlabel ;
var varnum name type length format informat label;
run;
Upvotes: 2