08-20-2015 09:27 AM
I'm generating data in SAS that I need to upload to an FTP site. I am currently exporting the data into csv files and manually transferring them to the FTP site. I keep searching for sample code to upload, but all I can seem to find are examples of reading data from an FTP site to use in SAS. I want to do the opposite. So, I have 2 question: 1) Is it possible to export a SAS dataset into a csv file and upload it to an FTP site simultaneously, and 2) would DCREATE() work with this process to create a new folder on an FTP server?
08-20-2015 09:41 AM
I found a lot of examples for sending files using FTP in the manual pages. SAS(R) 9.3 Statements: Reference
As to making a directory look at the NEW option. Or perhaps you could see if the FTP server on the target machine has a SITE command that will make a directory. Look at the RCMD option in the on-line manual page linked above.
08-20-2015 09:44 AM
Just use FILENAME FTP:
FILENAME ftpout FTP 'path_on_the_server' HOST='hostname' USER='username' PASS='password';
FILE ftpout dlm=';';
To create a line with the column names, use a
IF _N_ = 1 THEN DO; PUT "variable1;variable2;...."; END;
To create a remote folder dynamically, you may need to experiment with the RCMD option of FILENAME FTP. DLCREATE() works only on the local file system (and anything that is mounted there).
08-20-2015 09:54 AM
So here is an example.
%let pass=yyyy ;
filename outdir ftp 'new_dir' dir new host="&host" user="&user" pass="&pass" ;
set sashelp.class ;
file outdir('class.csv') dsd ;
put (_all_) ( ;
filename outdir clear ;