Home

Resume

My SAS

Research

My SAS

Family

Feedback

Home

 

My SAS - SAS Code


Back to SAS Code

Find files in a directory


SAS Code:

/*
     Find files with name including certain string in a directory
                  Songlin Zhu Ph.D.

          path: Directory where files stored
  search_string: string shown in those file names
        at_end: at_end = Y -- string located at the
                               end of a filename
                at_end ne Y -- don't care string location

  output:  File names saved in the data set named file_names
           in the work library
*/


dm 'log;clear;out;clear;';
libname scllib "C:\sasuser\cat";

%let path          = C:\sasuser\pgm;
%let search_string = .sas;
%let at_end        = Y;

dm 'af c=scllib.find_files.Find_files.scl';

%macro title_1;
   %if &at_end. = Y %then title2 "(Search string '&search_string.' is located at the end of a filename)";
   %else title2 "(Don't care location of search string '&search_string.')";

%mend title_1;


proc print data = work.file_names;
   title1 "List files in the directory of &path.";
   %title_1;

run;

A SCL program was invoked by above program. Download the SCL program and save it in the directory c:\sasuser\cat. If you want to save it in another directory, change c:\sasuser\cat into the directory you save the SCL program.

If you have any questions, feel free to send me feedback.