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!
When decompressing to stdout, use
gzip -dc filename
Appreciate your response!
I tried that too, still same issue.
FILENAME LGCY_GZ PIPE "gzip -dc /product/..../Infile.TXT.gz" lrecl=32767;
DATA Legacy_Test;
INFILE LGCY_GZ(OBS=5)
LRECL=32767
DLM='|'
MISSOVER
DSD;
INPUT
D_U_N_S_NUMBER : BEST9.
.....
....;
run;
I get this error:
"ERROR: Invalid device type."
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";
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.
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;
@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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.