Hello,
I would like to know , if we can use sas only to unzip a big file :big_file.zip( more than 4 GB), without using an unix commands or windows command.
- using sas only to unzip
- do not use any unix or windows command.
Thank you
Did you try using the FCOPY() command?
You could use the code below to copy a file named 'myfile.dat' from a zip file name 'myfile.zip'.
filename in zip 'myfile.zip' member='myfile.dat' recfm=f lrecl=1;
filename out 'myfile.dat' recfm=f lrecl=1;
data _null_;
rc=fcopy('in','out');
run;
@Tom This requires SAS 9.4+, correct?
@Tom: Thank you very much.
FCOPY() ? Not so much
To clarify my question.
I have a zip file REP.zip ( with more than 5 GB) under sas 9.2
/V1/V2/V3/REP.zip
Inside REP.zip, I have
REP.zip/DIR1
REP.zip/DIR2
............
...............
REP.zip/DIRn
REP.ZIP/f1.txt
...........
REP.zip/f20.txt
I want to unzip(=decmpress) a REP.ZIP in /Z1/Z2/Z3/REP
Note : in REP.ZIP , I do not have any sas file, all of them are an external file.
Thank you
SAS does't have unzip capabilities as far as I'm aware.
Did you try Tom's code and it didn't work? If so, post the log.
SAS can read text files from a zipped file, so if that's the reason for unzipping, maybe you can skip the unzip portion.
As with your other thread, this isn't a SAS issue, its the fact that your OS doesn't seem to have a tool to unzip the file. Have you tried command line with 7z? It's usually installed on many servers as well.
And you've still never answered if you can unzip the file outside of SAS successfully. You may have an issue with your file.
To reply to your question
"If I have tried to unzip the file outside of SAS successfully."
- Manually, yes, it works well successefully outside sas
- By unix command ? not yet, but I will test it and I will publish the answer.
Here , my question is "Using SAS only to unzip a big file ".
So, I want to use sas only to do this job( no unix and windows commands)
Thank you
@LineMoon wrote:
Here , my question is "Using SAS only to unzip a big file ".
So, I want to use sas only to do this job( no unix and windows commands)
What you want isn't possible.
There are workarounds, ie FCOPY, but not a direct unzip. That's a function for a utility, such as 7z, gzip or multiple other packages.
You can read from a ZIP file, but not unzip the file.
For Information: I have used "unzip the file outside of SAS " but it does not work.
Then your issue isn't with SAS, it's with your external utility.
If you are using SAS 9.2 then the answer is that you need to either upgrade to SAS 9.4 or unzip the file outside of SAS.
Just adjust the code I posted to names of the files you have. So if you have a zip file named '/V1/V2/V3/REP.zip' and you want the file inside of it that is named 'f1.txt' then just adjust the code to the use those names.
If you don't know the names of the members then use the DOPEN() and DREAD() functions to find the names.
filename myzip zip '/V1/V2/V3/REP.zip' ;
data members ;
did=dopen('myzip');
do memnum=1 to dnum(did);
length member $256 ;
member = dread(did,memnum);
output;
end;
did=dclose(did);
run;
@Tom: Thank you a lot.
I will test it.
Please, what 's about the output wanted. If I want to have this output
/Z1/Z2/Z3/REP/dir1
/dir2
/dir3
/dirn
So what's about the time of treatement for a big file (more than 5 GB) ? It will be very quickly ?
I know that's we can read a zip file in sas, but the aim ,here, is to have the output REP/dir1,......REP/dirn
Thank you
If you know the file structure/names and can use FCOPY, create a macro to loop through and extract to where you want them. You can create folders using DCREATE.
For information,
filename myzip zip '/V1/V2/V3/REP.zip' ;
it does not work in sas 9.2 ?
I get
ERROR :Invalide device type
ERROR: error in the filename steatement
I think you 9.3 for filename zip.
Unfortunately it appears you're stuck with external utilities. You need to talk to you DB administrator.
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.