BookmarkSubscribeRSS Feed
djbateman
Lapis Lazuli | Level 10

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?

3 REPLIES 3
Tom
Super User Tom
Super User

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.

Kurt_Bremser
Super User

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

Tom
Super User Tom
Super User

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 ;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 4488 views
  • 6 likes
  • 3 in conversation