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
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.