Hello,
I wanted to to create a zipped text file on a remote server using SAS. Base SAS 9.4 is running on a Unix platform while the remote server runs Windows. So far I used to create text files on the remote server directly using FILENAME FTP statement. I stumbled upon FILENAME ZIP statement to create files directly within zip archives. But this only seems to work for files I want to create locally. I tried running FILENAME FTP and ZIP in the same statement and they don't seem to work.
One approach I'd thought of was to use FILENAME ZIP to create text files within zip archives locally and then use a FTP script to copy these to the remote server.
I'd appreciate some pointers on getting this done natively through SAS, if at all that's possible.
Thanks!
@sauravs3n wrote:
Thanks Kurt!
I gave this a try but I got an error message saying Invalid option for recfm in the file statement.
I did some testing, and now I think this is the working version:
filename target ftp 'filename' host='host' user='user' pass='password';
filename source 'somefile.zip';
data _null_;
infile source recfm=n;
file target recfm=s;
input char $char1.;
put char $char1.;
run;
The $char formats are necessary to avoid conversion of dots to blanks (because SAS misunderstands this for missing values when only $1. is used).
After creating the zip file locally, you can use filename ftp with recfm=n to transfer the file:
filename target ftp 'filename' host='host' user='user' pass='password';
filename source 'somefile.zip';
data _null_;
infile source recfm=n;
file target recfm=n;
input char $1.;
put char $1.;
run;
(untested)
Personally, I'd prefer to use a external utility like sftp to transfer the zip file.
Thanks Kurt!
I gave this a try but I got an error message saying Invalid option for recfm in the file statement.
@sauravs3n wrote:
Thanks Kurt!
I gave this a try but I got an error message saying Invalid option for recfm in the file statement.
I did some testing, and now I think this is the working version:
filename target ftp 'filename' host='host' user='user' pass='password';
filename source 'somefile.zip';
data _null_;
infile source recfm=n;
file target recfm=s;
input char $char1.;
put char $char1.;
run;
The $char formats are necessary to avoid conversion of dots to blanks (because SAS misunderstands this for missing values when only $1. is used).
@Kurt_Bremser wrote:
@sauravs3n wrote:Thanks Kurt!
I gave this a try but I got an error message saying Invalid option for recfm in the file statement.
I did some testing, and now I think this is the working version:
filename target ftp 'filename' host='host' user='user' pass='password'; filename source 'somefile.zip'; data _null_; infile source recfm=n; file target recfm=s; input char $char1.; put char $char1.; run;
The $char formats are necessary to avoid conversion of dots to blanks (because SAS misunderstands this for missing values when only $1. is used).
This works great! Thanks!
One additional change I had to do while creating the text file within the zip archive locally was to add TERMSTR=CRLF to the file statement to enable the text file to display properly on windows. The text file would otherwise display all the data in a single line.
@sauravs3n wrote:
One additional change I had to do while creating the text file within the zip archive locally was to add TERMSTR=CRLF to the file statement to enable the text file to display properly on windows. The text file would otherwise display all the data in a single line.
This depends on the software used to display the text file. While notepad needs the additional CR, more advanced text editors like Notepad++ can handle it, like most (or all) of the word processors.
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.