The macro contained on the Full Code tab lists all of the files that contain a particular extension within a directory and all sub-directories. This macro can be modified to do more than just list the files. The %PUT can be replaced with other code to be used on each file. For example, if you want to %INCLUDE each file contained within these directories, you can do this easily by replacing the %PUT statement with the following:
%include "&dir\&name" /source2;
For a quick and easy way to just LIST the files, the following can be used instead of the macro:
Filename filelist pipe "dir /b /s c:\temp\*.sas"; Data _null_; Infile filelist truncover; Input filename $100.; Put filename=; Run;
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.
%macro drive(dir,ext);
%local filrf rc did memcnt name i;
/* Assigns a fileref to the directory and opens the directory */
%let rc=%sysfunc(filename(filrf,&dir));
%let did=%sysfunc(dopen(&filrf));
/* Make sure directory can be open */
%if &did eq 0 %then %do;
%put Directory &dir cannot be open or does not exist;
%return;
%end;
/* Loops through entire directory */
%do i = 1 %to %sysfunc(dnum(&did));
/* Retrieve name of each file */
%let name=%qsysfunc(dread(&did,&i));
/* Checks to see if the extension matches the parameter value */
/* If condition is true print the full name to the log */
%if %qupcase(%qscan(&name,-1,.)) = %upcase(&ext) %then %do;
%put &dir\&name;
%end;
/* If directory name call macro again */
%else %if %qscan(&name,2,.) = %then %do;
%drive(&dir\%unquote(&name),&ext)
%end;
%end;
/* Closes the directory and clear the fileref */
%let rc=%sysfunc(dclose(&did));
%let rc=%sysfunc(filename(filrf));
%mend drive;
/* First parameter is the directory of where your files are stored. */
/* Second parameter is the extension you are looking for. */
%drive(c:\temp,sas)
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.
Type: | Sample |
Date Modified: | 2012-03-02 15:07:38 |
Date Created: | 2012-02-27 09:34:37 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | Base SAS | Microsoft® Windows® for 64-Bit Itanium-based Systems | 9 TS M0 | |
Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9 TS M0 | |||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9 TS M0 | |||
Microsoft Windows 2000 Advanced Server | 9 TS M0 | |||
Microsoft Windows 2000 Datacenter Server | 9 TS M0 | |||
Microsoft Windows 2000 Server | 9 TS M0 | |||
Microsoft Windows 2000 Professional | 9 TS M0 | |||
Microsoft Windows NT Workstation | 9 TS M0 | |||
Microsoft Windows Server 2003 Datacenter Edition | 9 TS M0 | |||
Microsoft Windows Server 2003 Enterprise Edition | 9 TS M0 | |||
Microsoft Windows Server 2003 Standard Edition | 9 TS M0 | |||
Microsoft Windows XP Professional | 9 TS M0 | |||
64-bit Enabled AIX | 9 TS M0 | |||
64-bit Enabled HP-UX | 9 TS M0 | |||
64-bit Enabled Solaris | 9 TS M0 | |||
HP-UX IPF | 9 TS M0 | |||
Linux | 9 TS M0 | |||
OpenVMS Alpha | 9 TS M0 | |||
Tru64 UNIX | 9 TS M0 |