BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BenConner
Pyrite | Level 9

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

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

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=.

View solution in original post

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

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=.

BenConner
Pyrite | Level 9

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: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 779 views
  • 1 like
  • 2 in conversation