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?
@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.
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).
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
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.
SAS 9.4, TS 1M3 is my version.
Yes, I am trying to get the list of files in the zip file.
Thank you
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.
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
Try the macros here:
https://blogs.sas.com/content/sasdummy/2017/09/08/filename-zip-details/
Using Chris's code from GitHub here:
https://gist.github.com/cjdinger/04384420b1c04bdcd0e894d7950c7652
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 */
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...
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.