BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SAS_BI
Fluorite | Level 6

Hi there,

 

I tried to load a csv file from SAS to FTP, I used the code below:


filename FtpStg ftp "'Test.csv'" debug
host='ftp://XXXXXXXXXX'
user="Username" pass="password" RCMD='SITE RDW NOWRAPrecord READTAPEFORMAT=V' debug;


proc export data=Test
outfile=FtpStg
dbms=csv
replace;
run;

 

I got this message:

NOTE: Unable to connect to host ftp://XXXXXX Check validity of host name.
ERROR: Open failed for file FTPSTG  
ERROR: Host name ftp://XXX not found.
NOTE: The SAS System stopped processing this step because of errors.

 

 

Could someone help me on this?

 

Thank you in advance.

 

Best,

Salvatore

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

@SAS_BI

The aim here, it is to create a data set via SAS and after to load the data set to a location via FTP

 

That's where I'm coming from. Isn't the aim simply to copy a .csv from one location to another location. Why is it an aim to load it also into an intermediary SAS dataset?

 

Now the question is: Can your FTP server access the original source location or do you first need SAS (or a process running on the SAS server) to copy the .csv to a location accessible to the FTP server?

 

View solution in original post

11 REPLIES 11
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Sorry, are you writing a file out from SAS or readin to SAS as this: "I tried to load a csv file from FTP to SAS" implies you are reading a file in, but in your code you use proc export, which is a procedure to write a file out from SAS?  As for your error:

ERROR: Host name ftp://XXX not found.

Kind of tells you all there is, host is not found?  I assume you blanked something out, but if you can't show it then you need to resolve it with your IT.

DaveHorne
SAS Employee

Try taking the "ftp://" string out of the hostname (it should be just the name, ie host='server.company.com')

 

Some FTP examples:  http://support.sas.com/kb/43/962.html

SAS_BI
Fluorite | Level 6

I am sorry RW9, I have update the message, actually I want upload a SAS table to FTP and save it as CSV file.

 

Thank you again

SAS_BI
Fluorite | Level 6

Thank you DaveHorne, I have tried it but still I have the same issue.

 

ballardw
Super User

First please confirm that you have been able to login to the FTP site and upload another small file using an FTP or command line.

If that works, export an example SAS data set to a local file and then upload it to the same site using FTP commands. If that works make sure that the FILENAME parameters include the commands you give to manually upload.

 

Are you sure that your FTP login has all of RWD permissions? That might cause a failure if you only have RW and will fail with only R.

 

I am a little concerned about your parameters NOWRAPrecord READTAPEFORMAT=V. I would not expect the text file SAS creates with export to need such though I would worry about text vs binary file transfers. The options you use almost look like you expect an application to be reading the file as SAS writes it which may have all sorts of issues.

SAS_BI
Fluorite | Level 6

Thanks for your message.

 

I have tried to updalod a file via FTP command line and it works fine as you said.

 

After that I tried the following code:

 


filename server ftp 'XXXX.csv'
CD='XXXX'
HOST='XXXXXX'
user='XXXXX' pass='XXXX' ;

data _null_;
infile 'XXXX.csv' recfm=n ;
input x $char1. @@;
file server recfm=s ;
put x $char1. @@;
run;

 

I did the last example of from this link http://support.sas.com/kb/43/962.html

 

When I run the code above sas is freezing and I have to stop the process via Task Manager.

 

Do you know if there is any issue on my code?

 

Thank you again

Tom
Super User Tom
Super User

CSV files are text files so no need to get too cute in the transfer.

 

filename server ftp 'XXXX.csv' CD='XXXX'
  HOST='XXXXXX' user='XXXXX' pass='XXXX'
;

data _null_;
  infile 'XXXX.csv' ;
  file server;
  input;
  put _infile_;
run;

If that works then you can write your SAS dataset directly to the FTP file.

proc export dbms=csv file=server 
  data=x.y
;
run;
Patrick
Opal | Level 21

@SAS_BI

 

Ehhmm...? You want to copy a .csv from one location to another location via FTP. Why exactly want you have this intermediary step loading the data first into a SAS table? Why can't you just issue an FTP command for this (eventually called out of a SAS session via X command)?

SAS_BI
Fluorite | Level 6

Thanks Tom,

 

I have tried your code but unfortunately SAS is running and never stop.

 

@Patrick

The aim here, it is to create a data set via SAS and after to load the data set to a location via FTP. However I ma happy as well to save the data set as csv file in my local pc and after that load it to another location via FTP.

 

 

Patrick
Opal | Level 21

@SAS_BI

The aim here, it is to create a data set via SAS and after to load the data set to a location via FTP

 

That's where I'm coming from. Isn't the aim simply to copy a .csv from one location to another location. Why is it an aim to load it also into an intermediary SAS dataset?

 

Now the question is: Can your FTP server access the original source location or do you first need SAS (or a process running on the SAS server) to copy the .csv to a location accessible to the FTP server?

 

SAS_BI
Fluorite | Level 6

Hi Patrick, thanks for your reply.

Indeed the fast way it is to copy the .csv from one location to anothe location (FTP).

I have asked ICT to create a job to do this every day.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 11 replies
  • 4682 views
  • 0 likes
  • 6 in conversation