/*----- * group: Macro programming * purpose: Data about data */ /**html *

Most interesting information about a data set can be * determined using the attrn() and attrc() functions. *

*

Most interesting information about a data set's structure (it's columns and their * metadata) can be determined using the varattr() functions. * attr can be fmt, infmt, label, len, name, num, type *

*

It is my personal style to _not_ write macros to return individual metadata values. * Such macros are practically superfluous in my estimation.

*

* SAS functions are accessed from macro by using the macro function %sysfunc *

*

See your Online Help or Online Doc for more * information about available attributes and functions. The same information is available via SASHELP.V* views, DICTIONARY.* tables and Proc CONTENTS. *

*/ %macro metadata (data=); %local dsid i j attrcs attrns attr attrv varfuncs varfunc; %local varname varnum; %let attrcs = CHARSET DATAREP ENCRYPT ENGINE LABEL LIB MEM MODE MTYPE SORTEDBY SORTLVL SORTSEQ TYPE ; %let attrns = ANY ALTERPW ANOBS ARAND ARWU CRDTE GENMAX GENNEXT ICONST INDEX ISINDEX ISSUBSET LRECL LRID MODTE NDEL NLOBS NLOBSF NOBS NVARS PW RADIX READPW TAPE WHSTMT WRITEPW ; %let varfuncs = VARTYPE VARLEN VARLABEL VARFMT VARINFMT ; %let dsid = %sysfunc ( open ( &data ) ); %put ATTRC; %put -----; %let i = 1; %do %while (%scan(&attrcs, &i, %str( )) ne ); %let attr = %scan(&attrcs, &i, %str( )); %let attrv = %sysfunc (ATTRC(&dsid, &attr)); %put &attr = &attrv; %let i=%eval(&i+1); %end; %put; %put ATTRN; %put -----; %let i = 1; %do %while (%scan(&attrns, &i, %str( )) ne ); %let attr = %scan(&attrns, &i, %str( )); %let attrv = %sysfunc (ATTRN(&dsid, &attr)); %put &attr = &attrv; %let i=%eval(&i+1); %end; %put; %put Variable functions; %put ------------------; %do i = 1 %to %sysfunc(ATTRN(&dsid,NVARS)); %let j = 1; %put VARNUM = &i; %put VARNAME = %sysfunc (VARNAME(&dsid, &i)); %do %while (%scan(&varfuncs, &j, %str( )) ne ); %let varfunc = %scan(&varfuncs, &j, %str( )); %let attrv = %sysfunc (&VARFUNC(&dsid, &i)); %put &varfunc = &attrv; %let j=%eval(&j+1); %end; %put ----------------; %end; %let dsid = %sysfunc ( close ( &dsid ) ); %mend; %metadata (data=sashelp.class);