/******************************************************************************************** program: var_def.sas purpose: Creates a variable definition table for the input dataset(s). output: var_def_&dsn..lst, where &dsn. is the name of the SAS dataset for which the variable definition table is being created. author: Sunil K Gupta 21 FEB 2002 *********************************************************************************************/ %macro vardef( lib_d=work, /* Libref for the input dataset(s) */ dsn=, /* Dataset name */ lib_f=library, /* Libref for the format catalog */ sort_by=3, /* Indicates whether report is sorted (1) alphabetically by variable name, (2) by the position of variables in the dataset, or (3) both (produces two reports) */ save_f= /* Save to filename */ ); *options ls=181 ps=59 center pageno=1; options ls=80 ps=45 nocenter pageno=1; * Specify file name for table output.; %if %length(&save_f) > 0 %then %do; filename &dsn "C:\sasgroup\complementsoft\Programs\var_def_&dsn..lst"; proc printto new print=&dsn.; run; %end; * Create dataset from format library.; proc format lib=&lib_f cntlout=f_d; run; * Collect all variable information from the SAS dictionaries.; proc sql; create table c_d as select * from dictionary.columns where lowcase(libname)="&lib_d" and lowcase(memname)in ("&dsn"); create table cb_num as select c_d.*, f_d.start, f_d.end, f_d.label as fmtlabel, f_d.length as fmtlen from c_d left join f_d on substr(format,1,length(c_d.format)-1)=f_d.fmtname order by c_d.varnum, f_d.start; * Do each type of requested report.; %if &sort_by = 1 or &sort_by = 3 %then %do; data cb_name; set cb_num; run; proc sort data=cb_name; by name start; run; title1 "Variable Definition Table for &lib_d..&dsn"; title2 'Variables ordered alphabetically by name'; proc report nowindows headline headskip split=' ' ls=181 ps=59 data=cb_name; column name label type length start fmtlabel format informat; define name / order width=10; define type / order width=6; define length / order width=6 left; define label / order flow width=20; define format / display; define informat / display; define start / display right; define fmtlabel / display flow width=20; break after name / skip; run; %end; %if &sort_by > 1 %then %do; title1 "Variable Definition Table for &lib_d..&dsn"; title2 'Variables ordered by position in dataset'; proc report nowindows headline headskip split=' ' ls=181 ps=59 data=cb_num; column varnum name label type length start fmtlabel format informat; define varnum / order noprint; define name / order width=10; define type / order width=6; define length / order width=6 left; define label / order flow width=20; define format / display; define informat / display; define start / display right; define fmtlabel / display flow width=20; break after varnum / skip; run; %end; %mend; libname mydata 'C:\sasgroup\complementsoft\Programs'; libname library 'C:\sasgroup\complementsoft\Programs'; %vardef(lib_d=mydata, dsn=demog, save_f=demog);