BookmarkSubscribeRSS Feed
LineMoon
Lapis Lazuli | Level 10

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

13 REPLIES 13
Tom
Super User Tom
Super User

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;

   

Reeza
Super User

@Tom This requires SAS 9.4+, correct?

LineMoon
Lapis Lazuli | Level 10

@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

 

 

 

 

 

Reeza
Super User

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. 

 

 

 

 

LineMoon
Lapis Lazuli | Level 10

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

 

 

Reeza
Super User

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

LineMoon
Lapis Lazuli | Level 10

@Reeza

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

Reeza
Super User

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

Tom
Super User Tom
Super User

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;

 

 

 

LineMoon
Lapis Lazuli | Level 10

@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

 

 

 

 

Reeza
Super User

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. 

LineMoon
Lapis Lazuli | Level 10

@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

 

Reeza
Super User

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. 

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
  • 13 replies
  • 1285 views
  • 8 likes
  • 3 in conversation