BookmarkSubscribeRSS Feed
sas_student1
Quartz | Level 8

Hello,

I am trying to use SAS to FTP an XLSX file that I create via SAS.

 

I have a SAS code that I use to prepare a dataset that I then save and excel (XLSX) file. I need to FTP these file over every week, I want to set up an automated process that runs the data every week (this I already have set up) and in the automated process I would like to use SAS to FTP the XLSX file it prepares.

 

I have the host, user and pass. There is a folder (mailbox path) as well that I would like to use.

I tried using the below code that I found in the forum (the user, host, pass is censored, so is the 'mailboxpath') but the below didn't work. There was no log error either for me to troubleshoot the error.

Suggestions on what other code I can use (if the below code is not the way to go)

 

%let user=XXXX;
%let host=YYYY;
%let pass=ZZZZZ;
filename outdir ftp 'mailboxpath' dir new host="&host" user="&user" pass="&pass" ;

data _null_;
  set X.data ;
  file outdir('C:\Users\name\toexport.xlsx') xlsx ;
run;

 

 

3 REPLIES 3
Tom
Super User Tom
Super User

I thought you want to move the XLSX file.  Your data step is reading a SAS dataset and trying to write a text file.  Note that the FILE statement does not support the XLSX engine.  The XLSX engine only works when defining a LIBNAME.

 

What is the name of the existing XLSX file on the SAS host that you want to move to the remote host using FTP protocol? 

 

Do you really want to use the FTP protocol?  Most hosts now require you to use the more secure SFTP protocol instead.

 

japelin
Rhodochrosite | Level 12

Please check if you are able to access the site successfully via FTP.
You should be able to login and get the root directory with the following code.

If you are using a router, don't forget to specify passive mode.

filename dir ftp '' ls user="&user"  host="&host"  pass="&pass";
data _null_;
   infile dir;
   input;
   put _INFILE_;
run;

If you simply want to upload the file to ftp, you can use command prompt or powershell script to upload and run it with x command.

 

Reeza
Super User
1. Export your data set to your XLSX file to somewhere you have access. If you don't need to keep it, the work library is a good location.
2. Move the file using an appropriate method, FCOPY() but you probably want to use something more similar to this
https://communities.sas.com/t5/SAS-Programming/Move-files-between-server-using-SFTP/td-p/350673

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1595 views
  • 0 likes
  • 4 in conversation