BookmarkSubscribeRSS Feed
BeckyBell2355
Calcite | Level 5

Background:  We're trying to create a sas program (9.4) that combines multiple data .txt files (all same format) from one folder to create one large file.  The problem is not all .txt files in the folder should be included and the names differ too much that you can't fix it by specifying something like *ais.txt instead of *.txt.  We also want to reduce the number of changes needed in the program to run the program for other years.  The program below goes to a folder and lists the directory of all .txt files which are then all combined.

 

Question:  Is there a way to use .txt file that lists by line the specific names of the files you want to be combined like this:

R:\AIS\Final Files\2015\ais1.txt

R:\AIS\Final Files\2015\ais2.txt

R:\AIS\Final Files\2015\wierdname1.txt

and the program calls up that file (ais2015directory.txt) and loops through to combine the files listed? 

Or is there a better or easier way to do this where we can still use the same program for different years without making a lot of changes each year?

 

Does any of this make sense?  Thank you!

 

 


/*!!!!!Change Lib Directory*/

libname AIS15 'R:\AIS\Final Files\2015'; run;

/*!!! Change Directory*/

%let dirname = R:\AIS\Submissions\2015;

filename DIRLIST pipe "dir /B ""&dirname""\*.txt"; **the 2 sets of double quotes are needed here to allow for spaces in our file name;

data dirlist ;

length fname $256; 

infile dirlist length=reclen ;

input fname $varying256. reclen ;

run;




data AIS_auto (drop=fname);

length field1 $1. field2 $4. field3 $8. ;

set dirlist;

 filepath = "&dirname\"||fname;

infile dummy filevar = filepath length=reclen delimiter=',' end=done DSD MISSOVER lrecl=32767 firstobs=2;;

do while(not done);

myfilename = filepath;

input field1 field2 field3;

output;

end;

run;
4 REPLIES 4
Reeza
Super User

I've noticed you're using the FILEVAR option - can you  filter the list that gets fed to the input process?

 

 

BeckyBell2355
Calcite | Level 5

I think that's what I thought the seperate file which lists each of the files to use would do. 

 

The desire is to reduce the amount of changes in the coding since the file names and locations are different from year to year (and there's 11-13 different files to combine), so we can still use the same program for old and new years.

Thanks.

 

Reeza
Super User

It should...I don't quite follow how it's not working for you.

BeckyBell2355
Calcite | Level 5

Could you please show me example code of what you mean?  I'm still learning SAS as I go...  Thanks

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 608 views
  • 0 likes
  • 2 in conversation