/******************************************************************************
 * Programme : Makro dirfp2sas: Windows-Dateiliste in SAS-Tabelle
 * Reference : MAKROD8354
 * Source    : https://www.wearecas.eu/en/sampleCode/MAKROD8354
 ******************************************************************************/

/* --- BLOC 1 --- */
%macro dirfp2sas(filepattern,dsout);

  %local savopts;
  %let savopts=%sysfunc(getoption(NOTES));

  %if not %length(&dsout) %then %let dsout=_dirfp2sas;

  options nonotes;

  filename _dirfp pipe
  "echo off & for %nrstr(%f) in (""&filepattern"") do echo %nrstr(%f)";

/* --- BLOC 2 --- */
  data &dsout;
    length filename $ 300 lcfname $ 200;
    infile _dirfp;
    input;
    filename=trim(_infile_);
    lcfname=lowcase(scan(filename,-1,"\"));
  run;

/* --- BLOC 3 --- */
  filename _dirfp CLEAR;

  options &savopts;

%mend dirfp2sas;

