BookmarkSubscribeRSS Feed
mhollifi
Obsidian | Level 7

I need to read .7z file.  The contents of .7z file are more than thousand xml files.  I tried this but I got error like this.

118  filename inzip ZIP "e:\Users\mhollifi\Desktop\Chotibhak\USA_FO_Active_2016-04.7z";
119   
120  /* Read the "members" (files) from the ZIP file */
119   
     -
     180
ERROR 180-322: Statement is not valid or it is used out of proper order.

121  data contents(keep=memname isFolder);

122   length memname $200 isFolder 8;
      ------
      180

ERROR 180-322: Statement is not valid or it is used out of proper order.

123   fid=dopen("inzip");
      ---
      180

ERROR 180-322: Statement is not valid or it is used out of proper order.

124   if fid=0 then
      --
      180
ERROR 180-322: Statement is not valid or it is used out of proper order.

125    stop;

126   memcount=dnum(fid);
      --------
      180

ERROR 180-322: Statement is not valid or it is used out of proper order.

127   do i=1 to memcount;
      --
      180

ERROR 180-322: Statement is not valid or it is used out of proper order.

128    memname=dread(fid,i);
       -------
       180

ERROR 180-322: Statement is not valid or it is used out of proper order.

129    /* check for trailing / in folder name */
130    isFolder = (first(reverse(trim(memname)))='/');
       --------
       180

ERROR 180-322: Statement is not valid or it is used out of proper order.

131    output;
       ------
       180

ERROR 180-322: Statement is not valid or it is used out of proper order.

132   end;
      ---
      180

ERROR 180-322: Statement is not valid or it is used out of proper order.

133   rc=dclose(fid);
      --
      180

ERROR 180-322: Statement is not valid or it is used out of proper order.

134  run;

 

I suspect SAS cannot read .7z file.  Is it right?

10 REPLIES 10
Reeza
Super User

@mhollifi wrote:

 

 

I suspect SAS cannot read .7z file.  Is it right?


 

It supports GZIP (SAS 9.4 TS1M5)  files and/or files zipped with WINZIP. If you have XCMD enabled, you can always sneak down to your OS to have it unzip and export the file.

 

delete_winzip.JPG

Kurt_Bremser
Super User

When posting logs, use the {i} button. The main posting window removes much of the formatting and changes certain characters and character sequences, which removes a lot of important content of the log (like horizontal spacing, so the underlines of the ERROR message appear in the wrong place).

mhollifi
Obsidian | Level 7

So, SAS cannot read .7z files, I created a zip file for change.  I got this error message: "list handle creation failed" What is list handle? and Why failed to be created?  Thank you for your help.

 

45   filename inzip ZIP "e:\Users\mhollifi\Desktop\Chotibhak\USA_FO_Active_2016-04.zip";
46
47
48   data contents(keep=memname isFolder);
49    length memname $200 isFolder 8;
50    fid=dopen("inzip");
51    if fid=0 then
52     stop;
53    memcount=dnum(fid);
54    do i=1 to memcount;
55     memname=dread(fid,i);
56
57     isFolder = (first(reverse(trim(memname)))='/');
58     output;
59    end;
60    rc=dclose(fid);
61   run;

NOTE: List Handle Creation Failed.
NOTE: The data set WORK.CONTENTS has 0 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.01 seconds


62   title "Files in the ZIP file";
63   proc print data=contents noobs N;
64   run;

NOTE: No observations in data set WORK.CONTENTS.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

Reeza
Super User

What version of SAS do you have?

I'm assuming you're using the approach outlined here to list the files in your zipped file.

mhollifi
Obsidian | Level 7

SAS 9.4, TS 1M3 is my version.

Yes, I am trying to get the list of files in the zip file.

 

Thank you

Reeza
Super User

isFolder = (first(reverse(trim(memname)))='/'); 

 

The line above doesn't seem to match the code in teh blog post I linked. I would probably just copy that code and see if it worked as is....you only need the second part of the macro because you're not looking to find all zip files.

mhollifi
Obsidian | Level 7

Looks like nothing has been created/run in this step???? None of the "put" command produce print out. 

 

1    filename inzip ZIP "e:\Users\mhollifi\Desktop\Chotibhak\USA_FO_Active_2016-04.zip";
2
3
4    data contents(keep=memname isFolder);
5     length memname $200 isFolder 8;
6
7     fid=dopen("inzip"); put fid;
8     if fid=0 then
9      stop;
10    memcount=dnum(fid); put memcount;
11    do i=1 to memcount;
12     memname=dread(fid,i); put  fid memcount memname;
13
14     isFolder = (first(reverse(trim(memname)))='.');
15     output;
16    end;
17    rc=dclose(fid);
18   run;

NOTE: List Handle Creation Failed.
0
NOTE: The data set WORK.CONTENTS has 0 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds

mhollifi
Obsidian | Level 7

thank you for your help.  It didn't work. Maybe because the files names in the zip file are numbers?

741  /* Sample use */
742
743
744
745    %listzipcontents (targdir=e:\Users\mhollifi\Desktop\Chotibhak\USA_FO_Active_2016-04,
745! outlist=work.zipfiles);

NOTE: Numeric values have been converted to character values at the places given by:
      (Line):(Column).
      3:2
NOTE: Character values have been converted to numeric values at the places given by:
      (Line):(Column).
      2:11
NOTE: The data set WORK._ZIPFILES has 0 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.04 seconds
      cpu time            0.04 seconds


NOTE: Fileref TARGDIR has been deassigned.
NOTE: No rows were selected.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


ERROR: The data set list (WORK._contents:) does not contain any members.

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.ZIPFILES may be incomplete.  When this step was stopped there were 0
         observations and 0 variables.
WARNING: Data set WORK.ZIPFILES was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


NOTE: The file WORK._CONTENTS: (memtype=DATA) was not found, but appears on a DELETE statement.
NOTE: Deleting WORK._ZIPFILES (memtype=DATA).
746
747    %getZipDetails (inlist=work.zipfiles, outlist=work.zipdetails);

NOTE: PROCEDURE DATASETS used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds


ERROR: Table WORK.ZIPFILES doesn't have any columns. PROC SQL requires each of its tables to
       have at least 1 column.
ERROR: The following columns were not found in the contributing tables: memname, zip.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

 

ERROR: The data set list (WORK._deets:) does not contain any members.

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.ZIPDETAILS may be incomplete.  When this step was stopped there were
         0 observations and 0 variables.
WARNING: Data set WORK.ZIPDETAILS was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


NOTE: The file WORK._DEETS: (memtype=DATA) was not found, but appears on a DELETE statement.
NOTE: PROCEDURE DATASETS used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


748
749
750
751  */

 

Capture.JPG

mhollifi
Obsidian | Level 7

Thank you all for help.

I found out that both methods works when the number of members in the zip file is small amount.  I bombed because I have over 12thausands files in the zip file.  I don't think SAS can run through. 

 

I guess, I need to print files name to read them all manually...

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 10 replies
  • 1557 views
  • 2 likes
  • 3 in conversation