Good morning,
Was following Chris Hemedinger's example (blog) on reading members in a zip file. Works great as long as I have a hard-coded filename on the FILENAME statement. When I have multiple zip files to read and try to use the FILEVAR= option, the dsopen() function fails and returns a value of 0.
Am I seeing this correctly? If so I guess I can generate code that reads each of the zip files I need to extract member names for.
Thanks!
--Ben
I can iterate fine,
data HAVE;
ZIPFILE="%sysfunc(pathname(WORK))\z1.zip"; output;
ZIPFILE="%sysfunc(pathname(WORK))\z2.zip"; output;
run;
data WANT(keep=MEMNAME ZIPFILE);
set HAVE;
length MEMNAME $200 ;
RC=filename('inzip',ZIPFILE,'zip');
if RC then return;
FID=dopen('inzip');
if FID=0 then return;
MEMCOUNT=dnum(FID);
do I=1 to MEMCOUNT;
MEMNAME=dread(FID,I);
output;
end;
RC=dclose(FID);
run;
Since you are using file functions, using the filename() function makes more sense than using FILEVAR=.
I can iterate fine,
data HAVE;
ZIPFILE="%sysfunc(pathname(WORK))\z1.zip"; output;
ZIPFILE="%sysfunc(pathname(WORK))\z2.zip"; output;
run;
data WANT(keep=MEMNAME ZIPFILE);
set HAVE;
length MEMNAME $200 ;
RC=filename('inzip',ZIPFILE,'zip');
if RC then return;
FID=dopen('inzip');
if FID=0 then return;
MEMCOUNT=dnum(FID);
do I=1 to MEMCOUNT;
MEMNAME=dread(FID,I);
output;
end;
RC=dclose(FID);
run;
Since you are using file functions, using the filename() function makes more sense than using FILEVAR=.
Hi Chris,
Thank you so much! I just gave that a shot. It worked beautifully!
Beats the alternative I used (a series of call executes of a macro).
Much appreciated!
--Ben
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.