I am having difficulty trying to open a zipped SAS dataset. There seem to be very few examples of this that I can find online, and none of them offer a clue as to how to solve my problem.
If I run the following code, I can see that SAS is successfully recognizing the zip file and its contents (I edited out the path for anonymity, but "path" in the below is a valid path to an existing directory on the machine):
filename inzip ZIP "path\CoBISII-InterimAnalysis20190618.zip";
DATA contents(keep=memname);
length memname $200;
fid=dopen("inzip");
if fid=0 then
stop;
memcount=dnum(fid);
do i=1 to memcount;
memname=dread(fid,i);
output;
end;
rc=dclose(fid);
run;
PROC PRINT data=contents noobs N;
run;
This produces the following output:
memname |
---|
mrsdata.sas7bdat |
Readme.xlsx |
N = 2 |
I want to read the SAS dataset (mrsdata) into SAS. I tried following the example here and used the following code:
filename wc "%sysfunc(getoption(work))/mrsdata.sas7bdat";
DATA _null_;
infile inzip(mrsdata.sas7bdat) lrecl=256 recfm=F length=length eof=eof unbuf;
file wc lrecl=256 recfm=N;
input;
put _infile_ $varying256. length;
return;
eof:
stop;
run;
PROC CONTENTS data=WORK.mrsdata;
run;
However, this produces the following error (again, I am editing out the path for anonymity's sake):
ERROR: Open failure for path\CoBISII-InterimAnalysis20190618.zip during attempt to create a local file handle.
NOTE: UNBUFFERED is the default with RECFM=N.
NOTE: The file WC is:
Filename=C:\tmp\wc.dat,
RECFM=N,LRECL=256,File Size (bytes)=0,
Last Modified=24Jun2019:14:39:38,
Create Time=24Jun2019:14:39:38
I am at a complete loss as to how to proceed.
Your INFILE statement is missing quotes around the name of the member in the ZIP file.
infile inzip("mrsdata.sas7bdat") ...
I'm fairly certain that quotes there are not needed. There are plenty of examples online that don't use the quotes and seem to work. Further, if I use the quotes with my example, I get the same exact error message, it doesn't change the behavior at all.
That is too bad that quoting wasn't the issue, would have been a trivial fix.
You can also try adding the member name to the FILENAME statement. Use MEMBER="name".
Then it should be easier for you to use the FCOPY() function to extract the SAS7BDAT file. See Example 2.
Thanks for the suggestion. Unfortunately, I get the same error message:
rc=10005
msg=ERROR: Open failure for Z:\CRU\Pediatrics\Active Projects\CoBIS II\raw data\CoBISII-InterimAna
lysis20190618.zip during attempt to create a local file handle.
10005 is the error code returned by FCOPY; not sure if there is any meaning to be gleaned from that.
I do see that the documentation for FILENAME's ZIP access method states, "The ZIP access method reads and writes only files created with the WinZip file compression." I'm not sure how this .zip file was created, but I'm wondering if the issue was that it wasn't using WinZip.
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.
Ready to level-up your skills? Choose your own adventure.