/*** TIP 00398 ***/
/*** Dump A SAS Dataset to a Flat file ***/
Author: Ian Whitlock

/* flatfile2.sas - simplification of SI macro including doc */
%macro flatfile(lib=,dsn=,file=print,tl=3);
    %local putlist ;
    %let lib=%upcase(&lib);
    %let dsn=%upcase(&dsn);

    proc sql noprint ;
       select
         case
           when format ^= " " then
                name || " " || format
           when upcase(type) = "CHAR" then
                name || " $"||put(length,z3.)||"."
           else
                name || " best10."
         end  into :putlist separated by " +1 "
         from dictionary.columns
         where libname = "&lib" and memname = "&dsn"
       ;
       reset print ;
       title&tl "Layout for &lib..&dsn to &file" ;
       select name , type ,
         case
           when format ^= " " then trim(format)
           when upcase(type) = "CHAR" then "$"||put(length,z3.)||"."
           else "best10."
         end  || " +1 " as fmtlen
         from dictionary.columns
         where libname = "&lib" and memname = "&dsn"
       ;
       title&tl ;
    quit;

    data _null_;
      set &lib..&dsn;
      file &file ;
      put &putlist ;
    run;
%mend;


Typical usage might be:

%flatfile(lib=sasuser, dsn=houses)
/*** end of tip 00398 ***/