Thursday, March 26, 2015

SAS: FTP an external file (flat file)

I had a lot of trouble with SAS' FTP access engine. It appeared to be randomly corrupting the data.  This worked though. I relied heavily on the indicated web page, and then converted it to a macro.


* ----------------------------------------------------- ;
*              M A C R O :  F T P F I L E
* ----------------------------------------------------- ;
*  FTP the hard way...but to overcome failure of the
*  FTP access engine, which corrupted the data.
*  Source: https://communities.sas.com/message/114111
*  Bill Qualls, 20150326
* ----------------------------------------------------- ;

%macro ftpfile(folder=&RAWDATA_FOLDER, file=, ftpcom=&RAWDATA_FOLDER/ftpcom.txt);

* file to which ftp commands will be written ;
filename ftpcom "&FTPCOM" lrecl=80;

data _null_;
file ftpcom;

* ftp ession user and password ;
put "user theuser thepassword";

* disable prompting cmd ;
put "prom no";

* enable binary transfer mode cmd ;
put "bin";

* go to local folder cmd ;
put "lcd &FOLDER";

* go to remote folder cmd ;
put "cd OurFolderOnFTPServer";

* send file cmd ;
put "send &file";

run;


* set up piping into ftp commands into ftp instruction ;
filename doftp pipe "ftp -n ftp.xxxxxxxx.com < &FTPCOM";


* enable ftp session and pass it the commands file ;
data _null_;
infile doftp;
input;
put _infile_;
run;

%mend ftpfile;

No comments:

Post a Comment