Home > front end >  Pass file locations to Macro in SAS
Pass file locations to Macro in SAS

Time:10-28

I'm at the start of learning/using SAS so I'm hoping this is easy.. I just can't find any solutions, certainly not simple enough for me to understand at this stage!

I'm looking to pass the file names(full path) to a Macro I've already got working.

I can get the file names into a dataset, but is there a way to pass these names into the Macro so that it runs it for each file one at a time? Looking to 'process' each csv in a folder into the Macro individually.

My code is pretty simple:

Info I want to pass to the Macro-

Data fName; Run;

(A single column of 10 filepaths for example)

The Macro I want to 'push' these to is-

%processFiles(FileToProcess= '//example/test/file01.csv')

The simple data set works, the Macro works.. just can't figure out how to 'trigger' it for each file in that dataset.

Hopefully it's something easy.

Thanks

Tried several approaches; loops, passing as a list, nesting macros, etc.

CodePudding user response:

Use the dataset to generate the calls to the macro.

So if the dataset is named FILES and variable with the file name is called FNAME then you just need to run this data step to call the macro once for each file in the dataset.

data _null_;
  set files ;
  call execute('%nrstr(%processFiles)(FileToProcess='||quote(trim(fname),"'")||')');
run;
  • Related