LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (December 2001, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 10 Dec 2001 11:56:33 -0500
Reply-To:     Tom Frenkel <taf2@NYU.EDU>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Tom Frenkel <taf2@NYU.EDU>
Subject:      Re: can sas read zipped data file?
Comments: To: Min Qi Wang <mqw@GLUE.UMD.EDU>
In-Reply-To:  <Pine.GSO.4.21.0112081637440.5740-100000@z.glue.umd.edu>
Content-Type: TEXT/PLAIN; charset=US-ASCII

Mitch --

As someone else noted & as I verified by trying first, pipes were so slow (on my Win 2000 machine) as to be unusable. So here's some code I developed to read zipped files. It invokes DOS commands, and puts the unzipped files in a temporary directory, from where SAS reads them in.

I'm sorry that this code is not well annotated, and I don't have time to explain everything now; but let me know if you have questions & I'll try to help. Best,

--Tom Tom Frenkel <taf2@nyu.edu> http://homepages.nyu.edu/~taf2

options noxwait ls=80 /* ls=118 */ mprint source2 ; libname here '.' ; options errors=1 ; /* +++++++++++++++++++++ */

x c:\tools\warnxls.bat ;

OPTIONS XMIN ; /* Run `cmd.exe` minimized to avoid annoying flashes on screen */

/*-------------------------------------------------------*/ /* */ /* The following macro reads directly from Zipped */ /* files. */ /* */ /*-------------------------------------------------------*/

/*-------------------------------------------------------------------*/ %MACRO DOIT(year, suffix) ; /*-------------------------------------------------------------------*/

%let yy=%substr(&year, 3, 2) ; /* %let zipname =D:\&year\psu&yy.&suffix..zip; */ %let zipname =c:\projects\agb-school\Temp-Data\&year\psu&yy.&suffix..zip;

data _null_ ; file 'temp.bat' ; put " echo y | del c:\projects\agb-school\temp-unzipped\*.* > nul" ; put " c:\pkzip\pkzip25 -extr ""&zipname"" c:\projects\agb-school\temp-unzipped\ " ; * put " pause " ; run ;

x temp.bat ;

x dir /b c:\projects\agb-school\temp-unzipped\ > tempdir.out ;

data _null_ ; infile 'tempdir.out' truncover ; input name $ 1 - 40 ; /* file = scan(name, 1) ; */ file = name ; call symput('filename', file) ; run ;

title "SAS dataset ONEFILE, created from: zipname=&zipname, filename=&filename" ;

filename myfile 'c:\projects\agb-school\temp-unzipped\*.*' ; /* just 1 file */

DATA oneFILE ;

length default = 5 ; /* ++++++++++++++++++++ */

length zipname $ 50 ; length filename $ 30 ;

missing M N ;

retain zipname "&zipname" ; retain filename "&filename" ; retain year_taf &year ;

INFILE myfile Lrecl=20000 MISSOVER /*obs=100*/ ; /* +++++ */

%inc "input&YY..txt" ; /* Reads the input statement for the given year */

run ;

proc contents VARNUM data=oneFILE ; run ;

proc print data=oneFILE(obs=5) ; run ;

%if (&year=1997) and (&suffix=ai_dat) %then %do ; /* ++++++++++++++++++ */ data here.school ; set oneFILE ; ; %end ; %else %do ; data here.school ; set here.school oneFILE ; %end ;

run ;

/*-------------------------------------------------------------------*/ %MEND DOIT ; /*-------------------------------------------------------------------*/

/*=== %doit(1997, ai_dat) %doit(1997, kn_dat) %doit(1997, ow_dat)

%doit(1998, ai_dat) %doit(1998, kn_dat) %doit(1998, ow_dat)

%doit(1999, ai_dat) %doit(1999, kn_dat) %doit(1999, ow_dat) ===*/

On Sat, 8 Dec 2001, Min Qi Wang wrote:

> Hi: > > Can SAS read a raw data file that is zipped (like data.zip) with infile or > other libname command? > > Thank you! > > Mitch >


Back to: Top of message | Previous page | Main SAS-L page