Sample 25079: Perform a PROC PRINT for all data sets that exist in a directory
This sample uses a macro to print all data sets that exist in a
directory that you specify.
This macro searches for data sets with an extension of SAS7BDAT. If your data sets are from an earlier version of SAS the macro will have to be
modified. An example of this is changing SAS7BDAT to SD2.
When invoking the macro, the parameter value should contain the name of the directory (without the quotation marks) that contains your SAS data sets.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
options mprint;
%macro drive(dir);
/* Creates a fileref */
%let filrf=mydir;
/* Creates a libref */
%let librf=temp;
/* Assigns the libref of temp to the directory you passed in */
%let lib=%sysfunc(libname(&librf,&dir));
/* Assigns the fileref of mydir to the directory you passed in */
%let rc=%sysfunc(filename(filrf,&dir));
/* Opens the directory to be read */
%let did=%sysfunc(dopen(&filrf));
/* Returns the number of members in the directory you passed in */
%let memcnt=%sysfunc(dnum(&did));
%let cnt=0;
%do i = 1 %to &memcnt;
/* Return the extension of the dataset found */
%let lname=%qupcase(%qscan(%sysfunc(dread(&did,&i)),2,.));
/* Return the first name of the dataset found */
%let fname=%qscan(%qsysfunc(dread(&did,&i)),1,.);
/* Check to see if file has a dataset extension of SAS7BDAT */
/* SAS7BDAT may need to be changed based on the version of */
/* the SAS data set you are looking for. */
%if %upcase(&lname) = SAS7BDAT %then %do;
proc print data=&librf..&fname;
run;
%end;
%end;
/* Close the directory */
%let rc=%sysfunc(dclose(&did));
%mend drive;
/* Replace c:\test below with your own directory */
%drive(c:\test)
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
This sample uses a macro to do a PROC PRINT for all data sets that exist in a directory that you specify.
| Type: | Sample |
| Topic: | SAS Reference ==> Macro
|
| Date Modified: | 2010-04-20 14:13:43 |
| Date Created: | 2005-01-26 16:17:28 |
Operating System and Release Information
| SAS System | Base SAS | Tru64 UNIX | 6.12 | n/a |
| Solaris | 6.12 | n/a |
| Linux | 6.12 | n/a |
| HP-UX | 6.12 | n/a |
| HP-UX IPF | 6.12 | n/a |
| AIX | 6.12 | n/a |
| ABI+ for Intel Architecture | 6.12 | n/a |
| 64-bit Enabled HP-UX | 6.12 | n/a |
| 64-bit Enabled Solaris | 6.12 | n/a |
| 64-bit Enabled AIX | 6.12 | n/a |
| Windows | 6.12 | n/a |
| Microsoft® Windows® for 64-Bit Itanium-based Systems | 6.12 | n/a |
| OS/2 | 6.12 | n/a |
| OpenVMS Alpha | 6.12 | n/a |
| OpenVMS VAX | 6.12 | n/a |