BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sauravs3n
Fluorite | Level 6

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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

View solution in original post

5 REPLIES 5
Kurt_Bremser
Super User

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.

sauravs3n
Fluorite | Level 6

Thanks Kurt!

 

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

Kurt_Bremser
Super User

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

sauravs3n
Fluorite | Level 6

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

Kurt_Bremser
Super User

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

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
  • 5 replies
  • 834 views
  • 3 likes
  • 2 in conversation