Help using Base SAS procedures

FTP within SAS program

Reply
N/A
Posts: 0

FTP within SAS program

Hi All,

Wanted some help understanding use of ftp within a SAS program to transfer files from one machine to another. Right now I am trying to transfer from a windows machine to another windows machine which is a ftp server

Say I have a file C:\Folder1\test.txt on machine A and want to transfer this file to folder
B on the FTP server machine, can anybody point to what the syntax will be like.

I saw some examples like

filename myfile ftp
cd="\B" host="MyFTPHost" recfm=s
user="anonymous"
pass="";

I am not sure where do I specify the source content that I need to send through ftp. In my example where do I specify the source location C:\Folder1\test.txt?

Any help?

Thanks,
Neel
Super Contributor
Super Contributor
Posts: 3,174

Re: FTP within SAS program

Posted in reply to deleted_user
The "remote" FTP server must be configured for access on one or more volumes - normally one as I recall. You may be able to accommodate the rqmt within the FTP server configuration, however it would not be a drive-letter technique. Check with your FTP server admin, possibly a sub-domain maybe?

Scott Barry
SBBWorks, Inc.
N/A
Posts: 0

Re: FTP within SAS program

I was able to figure out how to write to a file on a remote host using ftp.

I used the code given below(It directly writes to remote file from ods. My previous post was little different use case. But right now I am trying to get this working)

----------------------------------------------------

data sasProgData;

INFILE "C:\SAS\Samples\ADDVAR.SAS" DLM = ';';

LENGTH SASProgramText $ 200 ;

INPUT SASProgramText;
run;


filename myfile ftp 'sasProg1.txt'
host="myhost.mydomain.com" recfm=s lrecl=80
user="myUser"
pass="myPass";

ods rtf file=myfile;

proc print data=sasProgData;
run;

ods listing close;

----------------------------------------------------

For the above to work, file sasProg1.txt has to be created on the remote machine before executing the program. Else it complains no physical file existing.

My question is how do I create file(and also folders) on the remote machine?
I want to create some specific folder structure during runtime and then write the files in appropriate folder on the remote machine.

Apprecite any help!

Thanks,
Neel
Super Contributor
Super Contributor
Posts: 3,174

Re: FTP within SAS program

Posted in reply to deleted_user
FIrst, you need to CLOSE the "ODS RTF" after the PROC PRINT. If you are still having errors with the FILENAME execution, reply with the COPY/PASTE info from your SAS execution log and provide specific error messages, along with the SAS log and the code being executed.

Then, if you need to create a remote server directory, you will need review the appropriate SAS companion guide and explore using the FILENAME PIPE engine to execute remote system commands. I have pasted the related UNIX companion guide - there is one for each supported platform, available at the SAS support http://support.sas.com/ website for reference and use.

Scott Barry
SBBWorks, Inc.


http://support.sas.com/documentation/cdl/en/hostunx/61879/HTML/default/pipe.htm
N/A
Posts: 0

Re: FTP within SAS program

Thanks for the response. I have the close statement for ODS. It was just that I was trying RTF because I was not getting the listing lines wrapped in text file.

So about FTP, when I don't have the file sasProg1.txt in FTP root folder of the remote machine I get the error "ERROR: Physical file does not exist, sasProg1.txt." . Part of log is given below.

------------------------------------------------------------------------------------
89 filename myfile ftp 'sasProg1.txt'
90 host="sashost.dag.com" recfm=s lrecl=80
91 user="Administrator"
92 pass=XXXXXXXXXXXXX;
93
94 ods listing file=myfile;
NOTE: 220 Microsoft FTP Service
ERROR: Physical file does not exist, sasProg1.txt.
95
96 proc print data=sasProgData;
97 run;

NOTE: There were 73 observations read from the data set WORK.SASPROGDATA.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds


98
99 ods listing close;
-----------------------------------------------------------------------------------------

I don't know how it is supposed to behave. I thought it is expecting the sasProg1.txt to exist locally in the current directory. So I created dummy file with name sasProg1.txt
in current directory where the SAS program is, Still it complained about physical file not existing. When I created the file sasProg1.txt on remote machine it works and writes the contents from proc print to it.
N/A
Posts: 0

Re: FTP within SAS program

Posted in reply to deleted_user
I am trying to do FTP after creating the file locally. I use the below code to create file locally
----------------------------------------------------------------
data sasProgData;

INFILE "C:\DAG\SAS\Samples\ADDVAR.SAS" DLM = ';';

LENGTH SASProgramText $ 200 ;

INPUT SASProgramText;
run;

ods listing file='C:\Neelam\ProgFiles\sasProg1.txt';

ods listing file=myfile;

proc print data=sasProgData;
run;

ods listing close;
-------------------------------------------------------------------------------

After this, if I want to ftp the locally created file to the remote server, can anybody help me to figure out how the syntax should be?

Appreciate any help.

Thanks,
Neelam
PROC Star
Posts: 1,760

Re: FTP within SAS program

Posted in reply to deleted_user
I didn't know the FTP filename engine could be used for ODS output, though you seem to have succeeded.
You can use the FTP filename in a data step to either:

- create an empty remote file and use the ODS to FTP output in post 1, like:
filename myftp ftp 'sasProg1.txt' ...;
data _null_; *create empty file before output;
file myftp;
put ' ';
run;
ods rtf file=myftp;
[.. create file ..]

- transfer the file you have created locally in the post above, like:
[.. create file ..]
ods listing close;
data _null_;
file myftp;
infile myfile;
input;
put _infile_;
run;
Ask a Question
Discussion stats
  • 6 replies
  • 302 views
  • 0 likes
  • 3 in conversation