SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
RichardDeVen
Barite | Level 11

I can get a list of files in a zip archive using DOPEN and DREAD.  However, when I try to MOPEN or FOPEN a compressed file, in order to use FINFO(id,"File size (bytes)"), the sysmsg() is "ERROR: Function execution error". 

 

Question: Is there a way to get the compressed sizes of the items in the zip file when using the ZIP engine?

 

Example:

 

%let zipfile = c:\temp\ziptest\transp\archive1.zip;

data members(keep=filename label='Entries in the zip archive');
  length fref $8 filename $1000;

  rc = filename(fref,symget('zipfile'),'ZIP');
  msg = sysmsg();

  if rc ^= 0 then put msg;
  if rc = 0;

  did = dopen(fref);
  msg = sysmsg();

  if did = 0 then put msg;

  if did then 
    do index = 1 to dnum(did);
      filename = dread(did,index);
      output;
    end;
run;

And then this step shows "ERROR: Function execution error"

data _null_;
  set members;
  length fref_source $8 msg $200;
  rc1 = filename (fref_source, "&zipfile", "ZIP", "member=" || quote(trim(filename)) || " recfm=N lrecl=65536");
  put 'NOTE: ' rc1= fref_source=;
  fid = fopen(fref_source);
  msg=sysmsg();
  put 'NOTE: FOPEN() ' fid= / msg;

  if fid then do;
    fsize_source = input(finfo(fid,'FILE SIZE (BYTES)'),best.);
    fid = fclose(fid);
  end;
  put fsize_source=;

  if rc1 = 0 then rc = filename (fref_source);
run;
1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

You can use FINFO with some special attributes to get the info. See this article for an example. Here's a snippet:

 

fId = fopen("&f","S");
if fID then
  do;
   infonum=foptnum(fid);
     do i=1 to infonum;
      infoname=foptname(fid,i);
      select (infoname);
       when ('Filename') filename=finfo(fid,infoname);
       when ('Member Name') membername=finfo(fid,infoname);
       when ('Size') filesize=input(finfo(fid,infoname),15.);
       when ('Compressed Size') compressedsize=input(finfo(fid,infoname),15.);
       when ('CRC-32') crc32=finfo(fid,infoname);
       when ('Date/Time') filetime=input(finfo(fid,infoname),anydtdtm.);
      end;    
   end;
 compressedratio = compressedsize / filesize;
 output;
 fId = fClose( fId );

 

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!

View solution in original post

1 REPLY 1
ChrisHemedinger
Community Manager

You can use FINFO with some special attributes to get the info. See this article for an example. Here's a snippet:

 

fId = fopen("&f","S");
if fID then
  do;
   infonum=foptnum(fid);
     do i=1 to infonum;
      infoname=foptname(fid,i);
      select (infoname);
       when ('Filename') filename=finfo(fid,infoname);
       when ('Member Name') membername=finfo(fid,infoname);
       when ('Size') filesize=input(finfo(fid,infoname),15.);
       when ('Compressed Size') compressedsize=input(finfo(fid,infoname),15.);
       when ('CRC-32') crc32=finfo(fid,infoname);
       when ('Date/Time') filetime=input(finfo(fid,infoname),anydtdtm.);
      end;    
   end;
 compressedratio = compressedsize / filesize;
 output;
 fId = fClose( fId );

 

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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
  • 1 reply
  • 909 views
  • 1 like
  • 2 in conversation