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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.