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?
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.
Just use FILENAME FTP:
FILENAME ftpout FTP 'path_on_the_server' HOST='hostname' USER='username' PASS='password';
DATA _NULL_;
SET dataset;
FILE ftpout dlm=';';
PUT variable_list;
RUN;
To create a line with the column names, use a
IF _N_ = 1 THEN DO; PUT "variable1;variable2;...."; END;
block.
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).
So here is an example.
%let user=xxxx;
%let pass=yyyy ;
%let host=zzzz;
filename outdir ftp 'new_dir' dir new host="&host" user="&user" pass="&pass" ;
data _null_;
set sashelp.class ;
file outdir('class.csv') dsd ;
put (_all_) (:) ;
run;
filename outdir clear ;
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.
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.