DATA Step, Macro, Functions and more

Marry Reading in stream of data with Zip files

Reply
Contributor
Posts: 29

Marry Reading in stream of data with Zip files

[ Edited ]

I like reading in streams of data like

filename IN1 '.\*.log';
data work.test;
attrib filename fn length=$256;
retain filename;
infile in1 filename=fn eov=eov length=l;
input line $varying200. l;
if _n_ eq 1 or eov then do;
filename = fn;
eov = 0;
end;
run;

and I learned about zip files using

filename inzip zip "&ziploc";

I there a way to read all (similar) data files from a zip file as a stream, like

 

data allData;
infile InZip(*.csv) ...;

 

Super User
Super User
Posts: 7,401

Re: Marry Reading in stream of data with Zip files

Sorry, question is a bit unclear.  You have a set of CSV files, do you want the CSV files themselves to be added to a ZIP file?  Or do you want the datasets you create from reading in the CSV files to be put into a ZIP file?  There is a difference.  Generally if you have files and want to put them in a zip then you would use the OS to do this (either by select all files and then add to zip or by x commands).  If you want the data to a zip, then you can use ods package to create and add files to a zip via SAS per:

http://blogs.sas.com/content/sasdummy/2014/01/28/create-zip-ods-package/

Super User
Posts: 6,938

Re: Marry Reading in stream of data with Zip files

Have you already taken a look at http://blogs.sas.com/content/sasdummy/2015/05/11/using-filename-zip-to-unzip-and-read-data-files-in-...

I guess there are some hints for you in there.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 29

Re: Marry Reading in stream of data with Zip files

reading it. thanks. Guess there is no way around to copy the csv files out of the zip file and then read them in.

 

So the set-up is one zip file with a lot of csv-files in that have the same columns.

Super User
Super User
Posts: 7,401

Re: Marry Reading in stream of data with Zip files

If thats the case, then you would have setup an import process for the zip file would you not?  I.e. your data transfer documentation would detail where you will save the ZIP file, how you will ensure the files are all extracted correctly, possibly it will also tell you how you will protect those files - i.e. so if you need to go back to them you can always do this.  Hence that data import (and validation) process would take care of getting the files ready, so nothing SAS related, in SAS you would just read in the data.

Ask a Question
Discussion stats
  • 4 replies
  • 186 views
  • 0 likes
  • 3 in conversation