05-03-2016 01:53 PM
I have had some great help on this board and Chris helped me with finding the right path to connect to a shared drive and finding the zipped files. I have 12 folders that have multiple zipped files and I was coding each zipped file as I will show in my code and each .txt file I need from the zipped file. But there are over 200 .txt files in this one zipped folder and I only need the files that have the extension detail.txt. The other files I can disregard. They are flagged.txt. Here is an example of what I have as code now and just want to find an easier way than going back and forth to the shared drive and typing in all these lengthy names:
filename fromzip zip '\\agpcorp\files\va1\Private\managedcaresvcs\health-qualitymgmt\hedis rates_datasets_benchmarks\hedis 2017\datasets\2016_03_mar hedis 2017_my2016\me1\hedis2017_mar2016_md medicaidchip.zip';
length memname $256;
input memname $;
infile fromzip memvar=memname end=eof;
do while(not eof);
put memname= _infile_;
05-09-2016 12:00 AM
Hi @tmcrouse, it seems like you might need a two-pass approach for this. First pass is to assemble the list of TXT files that you need to process, and then for each text file you find, generate a SAS program that does the work of reading in the data from it. You don't say whether all of the text files have the same format -- it would be good if they do, as that will make things much easier.
Code might look something like this...
filename fromzip zip 'c:\temp\class.zip'; data contents(keep=memname isFolder); length memname $200 isFolder 8; fid=dopen("fromzip"); if fid=0 then stop; memcount=dnum(fid); do i=1 to memcount; memname=dread(fid,i); /* check for trailing / in folder name */ isFolder = (first(reverse(trim(memname)))='/'); output; end; rc=dclose(fid); run; options source2; filename sasprog temp; data _null_; file sasprog; length line $ 100; set contents(keep=memname); lines = 'data in; infile intxt(' || memname || '); input; put _infile_; run;'; put 'filename intxt ZIP "c:\temp\class.zip";' ; put line; put 'filename intxt clear;'; run; %include sasprog;