DATA Step, Macro, Functions and more

import xml file compressed into .7z

Reply
Contributor
Posts: 41

import xml file compressed into .7z

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?

Super User
Posts: 24,012

Re: import xml file compressed into .7z


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

Super User
Posts: 10,574

Re: import xml file compressed into .7z

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

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 41

Re: import xml file compressed into .7z

Posted in reply to KurtBremser

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

Super User
Posts: 24,012

Re: import xml file compressed into .7z

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.

Contributor
Posts: 41

Re: import xml file compressed into .7z

SAS 9.4, TS 1M3 is my version.

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

 

Thank you

Super User
Posts: 24,012

Re: import xml file compressed into .7z

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.

Contributor
Posts: 41

Re: import xml file compressed into .7z

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

Super User
Posts: 24,012

Re: import xml file compressed into .7z

Contributor
Posts: 41

Re: import xml file compressed into .7z

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)Smiley SadColumn).
      3:2
NOTE: Character values have been converted to numeric values at the places given by:
      (Line)Smiley SadColumn).
      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._contentsSmiley Happy 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._deetsSmiley Happy 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

Contributor
Posts: 41

Re: import xml file compressed into .7z

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

Ask a Question
Discussion stats
  • 10 replies
  • 233 views
  • 2 likes
  • 3 in conversation