Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting specific files from multiple directories...

Status
Not open for further replies.

billmo

Programmer
Feb 4, 2004
4
US
I'm familiar with wildcards in the filename statement that allows you to identify more than one file in a folder:

filename test "c:\main\sub1\*.txt";

However, I need to select specific files from multiple folders:

filename test ("c:\main\sub1\*.txt","c:\main\sub2\*.txt", ... "c:\main\sub50\*.txt");

In order to make the code more manageable, is there anyway to use a wildcard for a directory name or somehow look in all folders in a directory for the specific files?

Thank you.
billmo
 
Billmo,

I am not sure of what you intend to do with the info, but I may have an old DOS trick that may help you. Use the pipe option in the filename statement like this:

filename test pipe "dir c:\your_top_level_folder\*.txt /b /s";

data your_new_data;
infile test;
length filepath $500;
input filepath &;
run;

You can do some processing once you have found the full path to the file that you need.

I hope that this helps you. If you post more of what you need your program to do perhaps I can give you a better algorithm.

Klaz
 
This isn't going to be much help, however, I can confirm that there is a way to do it and I've done it in the past, however that was at a previous job, and I don't have the code for it anymore. I'll have a look on SAS Support and see if I can find anything.
 
Perhapse you can explain the need for the mult. files under one filename statement. Is this an AF program and you want to have an aggregate OPEN (a list of file in an open window) using the file handle?
Klaz
 
Thank you for your response. I'll try to explain my program a little better. I am receiving daily data files organized inside of folders for each day, inside of folders for each month. Since the files are named the same every day, I cannot dump everything into one folder without renaming each file. But in each daily folder, there are about six different types of files. I need to read one (or two) file from each folder into the same dataset in SAS. The work around has been to specify the path for every daily folder I want to read from, but this makes the code quite lengthy and is time consuming to update when I want to use the program for a new time period. I will test the DOS code. Hopefully that will do the trick. Thanks again.

billmo
 
Billmo,
I had to write the same type of program that you're describing. I found that via the macro engine the code was very short and managable. All that needed to be changed was the year & month. This was done at the top of the programm. When I had to hand the program to a non-programmer I created a SAS/AF GUI that required the year and the month to be entered/Chosen.

Klaz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top