DATA Step, Macro, Functions and more

Upload to FTP Using SAS Code

Regular Contributor
Posts: 220

Upload to FTP Using SAS Code

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?

Super User
Super User
Posts: 6,500

Re: Upload to FTP Using SAS Code

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.

Super User
Posts: 6,939

Re: Upload to FTP Using SAS Code


FILENAME ftpout FTP 'path_on_the_server' HOST='hostname' USER='username' PASS='password';


SET dataset;

FILE ftpout dlm=';';

PUT variable_list;


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

Maxims of Maximally Efficient SAS Programmers
Super User
Super User
Posts: 6,500

Re: Upload to FTP Using SAS Code

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_) (Smiley Happy ;


filename outdir clear ;

Ask a Question
Discussion stats
  • 3 replies
  • 3 in conversation