DATA Step, Macro, Functions and more

Create text file within a zip archive on a remote server using SAS

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Create text file within a zip archive on a remote server using SAS

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!


Accepted Solutions
Solution
‎07-11-2017 03:22 AM
Super User
Posts: 6,928

Re: Create text file within a zip archive on a remote server using SAS


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

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Super User
Posts: 6,928

Re: Create text file within a zip archive on a remote server using SAS

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
New Contributor
Posts: 3

Re: Create text file within a zip archive on a remote server using SAS

Thanks Kurt!

 

I gave this a try but I got an error message saying Invalid option for recfm in the file statement.

Solution
‎07-11-2017 03:22 AM
Super User
Posts: 6,928

Re: Create text file within a zip archive on a remote server using SAS


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

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
New Contributor
Posts: 3

Re: Create text file within a zip archive on a remote server using SAS


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

Super User
Posts: 6,928

Re: Create text file within a zip archive on a remote server using SAS


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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 79 views
  • 3 likes
  • 2 in conversation