DATA Step, Macro, Functions and more

Using SAS Only to unzip a big file

Reply
Super Contributor
Posts: 371

Using SAS Only to unzip a big file

[ Edited ]

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

Super User
Super User
Posts: 7,076

Re: Using SAS Only to unzip a big file

[ Edited ]

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;

   

Super User
Posts: 19,869

Re: Using SAS Only to unzip a big file

@Tom This requires SAS 9.4+, correct?

Super Contributor
Posts: 371

Re: Using SAS Only to unzip a big file

[ Edited ]

@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

 

 

 

 

 

Super User
Posts: 19,869

Re: Using SAS Only to unzip a big file

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. 

 

 

 

 

Super Contributor
Posts: 371

Re: Using SAS Only to unzip a big file

[ Edited ]

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

 

 

Super User
Posts: 19,869

Re: Using SAS Only to unzip a big file


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. 

Super Contributor
Posts: 371

Re: Using SAS Only to unzip a big file

[ Edited ]

@Reeza

For Information: I have used "unzip the file outside of SAS " but it does not work.

Super User
Posts: 19,869

Re: Using SAS Only to unzip a big file

Then your issue isn't with SAS, it's with your external utility. 

Super User
Super User
Posts: 7,076

Re: Using SAS Only to unzip a big file

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;

 

 

 

Super Contributor
Posts: 371

Re: Using SAS Only to unzip a big file

@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

 

 

 

 

Super User
Posts: 19,869

Re: Using SAS Only to unzip a big file

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. 

Super Contributor
Posts: 371

Re: Using SAS Only to unzip a big file

@Tom

 

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

 

Super User
Posts: 19,869

Re: Using SAS Only to unzip a big file

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. 

Ask a Question
Discussion stats
  • 13 replies
  • 389 views
  • 8 likes
  • 3 in conversation