BookmarkSubscribeRSS Feed
Ram_Bravos
Calcite | Level 5

Could not import a huge text file zipped as 'file.txt.gz'.

Tried "filename file_ref Pipe 'gzip -c filepath';" and getting "ERROR: Invalid device type." while trying to read it using infile and input statements(Data Step).

 

Any help is Appreciated!

 

6 REPLIES 6
Ram_Bravos
Calcite | Level 5

 

Appreciate your response!

 

I tried that too, still same issue.

 

 

 

 

Kurt_Bremser
Super User

Do you have XCMD enabled? Run

proc options;
run;

and search for "XCMD" in the log.

filename pipe only works when XCMD is enabled.

 

But you can try filename zip:

filename lgcy_gz zip "/product/....../infile.txt.gz";

 

Ram_Bravos
Calcite | Level 5

Ran Proc Options and i could see 'XCMD' in the log.

 

Tried (FILENAME LGCY_GZ ZIP "/product/sas-shared/...../file.txt.gz" lrecl=32767;) getting the error below.

 

ERROR: The file "/product/sas-shared/......./TWC_LEGACY1.TXT.gz" exists and is not a zip file. The output
file must be a zip file.

Patrick
Opal | Level 21

@Ram_Bravos

Unlike in your previous post you're now trying to use the ZIP engine. For this to work you would need a ZIP and not a GZ archive. 

Stick to the PIPE.

 

First thing to do: Use Putty or the like and make your GZIP command work without any SAS involvement. Once that works stick the command into pipe using the SAS Filename command as you've already started doing.

FILENAME LGCY_GZ PIPE "gzip -dc /product/..../Infile.TXT.gz" lrecl=32767;

 

Make sure you're using a length for lrecl long enough for the file you want to read (infile.txt). lrecl may be longer than 32767.

 

And for a first test using SAS I'd go for code as below:

filename lgcy_gz pipe "gzip -dc /product/..../infile.txt.gz" lrecl=32767;
data legacy_test;
  infile lgcy_gz;
  input;
  put _infile_;
  stop;
run;
Kurt_Bremser
Super User

@Ram_Bravos wrote:

Ran Proc Options and i could see 'XCMD' in the log.

 

Tried (FILENAME LGCY_GZ ZIP "/product/sas-shared/...../file.txt.gz" lrecl=32767;) getting the error below.

 

ERROR: The file "/product/sas-shared/......./TWC_LEGACY1.TXT.gz" exists and is not a zip file. The output
file must be a zip file.


So you are forced to use the external gzip.

 

Do this:

filename oscmd pipe "gzip -d /product/..../Infile.TXT.gz 2>&1";

data _null_;
infile oscmd;
input;
put _infile_;
run;

filename oscmd clear;

You will see all messages created by the system call in your SAS log.

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
  • 6 replies
  • 1214 views
  • 0 likes
  • 3 in conversation