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 Macro Language: Reference.
libname printlib 'SAS-data-library';
libname proclib 'SAS-data-library';
options nodate pageno=1 linesize=80 pagesize=60;
|
proc datasets library=proclib memtype=data nolist;
copy out=printlib;
select delay internat;
run; |
|
%macro printall(libname,worklib=work); |
|
%local num i; |
|
proc datasets library=&libname memtype=data nodetails;
contents out=&worklib..temp1(keep=memname) data=_all_ noprint;
run; |
|
data _null_;
set &worklib..temp1 end=final;
by memname notsorted;
if last.memname;
n+1;
call symput('ds'||left(put(n,8.)),trim(memname)); |
|
if final then call symput('num',put(n,8.)); |
|
run; |
|
%do i=1 %to #
proc print data=&libname..&&ds&i noobs;
title "Data Set &libname..&&ds&i";
run;
%end;
%mend printall; |
|
options nodate pageno=1 linesize=70 pagesize=60;
%printall(printlib) |
Printing All the Data Sets in a SAS Library: Listing Output
Data Set printlib.DELAY 1
flight date orig dest delaycat destype delay
114 01MAR08 LGA LAX 1-10 Minutes Domestic 8
202 01MAR08 LGA ORD No Delay Domestic -5
219 01MAR08 LGA LON 11+ Minutes International 18
622 01MAR08 LGA FRA No Delay International -5
132 01MAR08 LGA YYZ 11+ Minutes International 14
271 01MAR08 LGA PAR 1-10 Minutes International 5
302 01MAR08 LGA WAS No Delay Domestic -2
114 02MAR08 LGA LAX No Delay Domestic 0
202 02MAR08 LGA ORD 1-10 Minutes Domestic 5
219 02MAR08 LGA LON 11+ Minutes International 18
622 02MAR08 LGA FRA No Delay International 0
132 02MAR08 LGA YYZ 1-10 Minutes International 5
271 02MAR08 LGA PAR 1-10 Minutes International 4
302 02MAR08 LGA WAS No Delay Domestic 0
114 03MAR08 LGA LAX No Delay Domestic -1
202 03MAR08 LGA ORD No Delay Domestic -1
219 03MAR08 LGA LON 1-10 Minutes International 4
622 03MAR08 LGA FRA No Delay International -2
132 03MAR08 LGA YYZ 1-10 Minutes International 6
271 03MAR08 LGA PAR 1-10 Minutes International 2
302 03MAR08 LGA WAS 1-10 Minutes Domestic 5
114 04MAR08 LGA LAX 11+ Minutes Domestic 15
202 04MAR08 LGA ORD No Delay Domestic -5
219 04MAR08 LGA LON 1-10 Minutes International 3
622 04MAR08 LGA FRA 11+ Minutes International 30
132 04MAR08 LGA YYZ No Delay International -5
271 04MAR08 LGA PAR 1-10 Minutes International 5
302 04MAR08 LGA WAS 1-10 Minutes Domestic 7
114 05MAR08 LGA LAX No Delay Domestic -2
202 05MAR08 LGA ORD 1-10 Minutes Domestic 2
219 05MAR08 LGA LON 1-10 Minutes International 3
622 05MAR08 LGA FRA No Delay International -6
132 05MAR08 LGA YYZ 1-10 Minutes International 3
271 05MAR08 LGA PAR 1-10 Minutes International 5
114 06MAR08 LGA LAX No Delay Domestic -1
202 06MAR08 LGA ORD No Delay Domestic -3
219 06MAR08 LGA LON 11+ Minutes International 27
132 06MAR08 LGA YYZ 1-10 Minutes International 7
302 06MAR08 LGA WAS 1-10 Minutes Domestic 1
114 07MAR08 LGA LAX No Delay Domestic -1
202 07MAR08 LGA ORD No Delay Domestic -2
219 07MAR08 LGA LON 11+ Minutes International 15
622 07MAR08 LGA FRA 11+ Minutes International 21
132 07MAR08 LGA YYZ No Delay International -2
271 07MAR08 LGA PAR 1-10 Minutes International 4
302 07MAR08 LGA WAS No Delay Domestic 0
Data Set printlib.INTERNAT 2
flight date dest boarded
219 01MAR08 LON 198
622 01MAR08 FRA 207
132 01MAR08 YYZ 115
271 01MAR08 PAR 138
219 02MAR08 LON 147
622 02MAR08 FRA 176
132 02MAR08 YYZ 106
271 02MAR08 PAR 172
219 03MAR08 LON 197
622 03MAR08 FRA 180
132 03MAR08 YYZ 75
271 03MAR08 PAR 147
219 04MAR08 LON 232
622 04MAR08 FRA 137
132 04MAR08 YYZ 117
271 04MAR08 PAR 146
219 05MAR08 LON 160
622 05MAR08 FRA 185
132 05MAR08 YYZ 157
271 05MAR08 PAR 177
219 06MAR08 LON 163
132 06MAR08 YYZ 150
219 07MAR08 LON 241
622 07MAR08 FRA 210
132 07MAR08 YYZ 164
271 07MAR08 PAR 155
Copyright © 2010 by SAS Institute Inc., Cary, NC, USA. All rights reserved.