This is controlled by the macro %DO loop. The macro is created so that a separate DATA step is run for each file to be read from the directory. The last macro variable is created after all observations of the path and names have been read in order to place the total count of files that will be read into a macro variable called MAX. The second CALL SYMPUTX creates macro variables that each contains the name of the file that is used in the DATA statement to create a unique SAS data set for each file read.
The COUNT variable is used to create separate macro variables for each path and name combination. The first CALL SYMPUTX creates macro variables that each contains the full path and name of each file to read. A variable called COUNT is created to increment each time an observation is read to keep track of how many files there are. In the SET statement, the END= option is used to create a variable that indicates when you have reached the end of a data set. The next DATA step uses _NULL_ in the DATA statement to avoid creating a SAS data set since the purpose of this step is to create macro variables. The first DATA step is used to get the directory information to create a data set that contains each full pathname of all the files with a. The names are:įile1.csv, file2.csv, file3.csv, and file4.csv. This sample assumes that there are four comma-delimited files in the folder C:\_today\. To view the SAS log showing the execution of the sample program, click the Results tab. Then, use macro code with a %DO loop to execute a DATA step separately to read each of all files in the directory. Use the PIPE engine in the FILENAME statement to access the directory information.
#Read output files created in spss 12 how to#
The sample code on the Full Code tab shows how to read all files in a directory and create separate SAS data sets with unique names.