BeOptimized - Tips and Tricks

Read all files of a directory

SAS macro language allows you to process dynamically all the files of a directory or all the files of a library . Different technic exist depending on the nature of the files. This tips and tricks discuss the case when your files are datasets present in a single library and discuss the case when we manipulate flat files in a folder structure.

Details

You have created a code which allows you to do a data manipulation on a specific dataset and would like to apply this on all the datasets of a library or have created a SAS code which import a flat file and would like to import all the flat files of a directory (with the hypothesis that all the flat files have same layout). You could always embed the code in a macro and then call it for every dataset or flat file but what would happen if you would like to do it dynamically by scanning all the files automatically?
In this tips and tricks we will discuss 2 methods to read files in a folder: the pipe and the %do loop and then see how we could use dictionary tables to read all the datasets of a library.

Prerequisites

You have some SAS experience and know how to program a Data Step. You have to execute the same code for a list of files.


Go back to your selection


This site uses cookies. .

By continuing to browse the site you are agreeing to our use of cookies. Review our cookies information for more details.