Chapter Contents

Previous

Next
The PRINT Procedure

Example 9: Printing All the Data Sets in a SAS Library


Features:
Macro facility
DATASETS procedure
PRINT procedure
Data set: EXPREV and LIST

This example prints all the data sets in a SAS library. You can use the same programming logic with any procedure. Just replace the PROC PRINT step near the end of the example with whatever procedure step you want to execute. The example uses the macro language. For details about the macro language, see SAS Guide to Macro Processing, Version 6, Second Edition.


Program

libname printlib 'SAS-data-library'
options nodate pageno=1 linesize=80 pagesize=60;
 Note about code
proc datasets library=work memtype=data nolist;
   copy out=printlib;
      select list exprev;
run;
 Note about code
%macro printall(libname,worklib=work);






 Note about code
   %local num i;
 Note about code
   proc datasets library=&libname memtype=data nodetails;
      contents out=&worklib..temp1(keep=memname) data=_all_ noprint;
   run;









 Note about code
   data _null_;
      set &worklib..temp1 end=final;
      by memname notsorted;
      if last.memname;
      n+1;
      call symput('ds'||left(put(n,8.)),trim(memname));



 Note about code
      if final then call symput('num',put(n,8.));



 Note about code
   run;


 Note about code
   %do i=1 %to #
      proc print data=&libname..&&ds&i noobs;
         title "Data Set &libname..&&ds&i";
      run;
   %end;
%mend printall;
 Note about code
options nodate pageno=1 linesize=70 pagesize=60;
%printall(printlib)


Output
[HTML Output]  [Listing Output]


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.