/* flatfile2.sas - simplification of SI macro including doc */ /* From Ian Whitlock, Westat, on SAS-L, 4-99 */ /* Converts a SAS dataset to a fixed format flat file and writes a "documentation" report. Parm names and style converted for consistency with our conventions. spaces parm added. Typical usage might be: %flatfile(lib=sasuser, sasdsn=houses) Could use work to improve the output layout report. Would also be nice if the input parms for lib and sasdsn could be combined into a single setin and we could parse it and figure out which was which. */ %macro flatfile(lib=, /* libref of input sas dataset to convert */ sasdsn=, /* second-level sas dataset name */ file=print, /* name of file to write to */ tl=3, /* default is to generate a title3 stmt */ spaces=1 /* number of spaces separating output fields */ ); %local putlist ; %let lib=%upcase(&lib); %let sasdsn=%upcase(&sasdsn); proc sql noprint ; select case when format ^= " " then name || " " || format when upcase(type) = "CHAR" then name || " $char"||trim(left(put(length,3.)))||"." else name || " best10." end into :putlist separated by " +&spaces " from dictionary.columns where libname = "&lib" and memname = "&sasdsn" ; reset print ; title&tl "Layout for &lib..&sasdsn to &file" ; select name , type , case when format ^= " " then trim(format) when upcase(type) = "CHAR" then "$"||trim(left(put(length,3.)))||"." else "best10." end || " +&spaces " as fmtlen from dictionary.columns where libname = "&lib" and memname = "&sasdsn" ; title&tl ; quit; data _null_; set &lib..&sasdsn; file &file ; put &putlist ; run; %mend;