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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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