DATA Step, Macro, Functions and more

Create a csv file in SFTP server

Reply
Contributor
Posts: 70

Create a csv file in SFTP server

Hi,

 

I want to create one of the sas datset in SFTP server in CSV format.I tried below test code to create file in SFTP server,but i could not connect to FTP server.

 

I also tried to connect to SFTP with libname statement but even that not work.

 

FILENAME targetSFTP "/xx/test.csv" HOST = 'xx-xx.xx.xx.com' DEBUG;

data _null_;

file target;

do i=1 to 10;

put i=;

end;

run;

 

Please help me to get it done in two ways with filename and libname.

 

Thanks in advance

 

regards,

ravi

 

Super User
Posts: 9,919

Re: Create a csv file in SFTP server

To use filename sftp, password-free authentication needs to be in place. Make sure that you have public/private key authentication set up for the userID's involved.

 

Also post the log for steps that don't work. Without the log, everything else is guesswork.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 70

Re: Create a csv file in SFTP server

Posted in reply to KurtBremser

Hi Kurt,

Thans for your quick response.I did not understand this public and private keys.

 

But i have username and password for this SFTP server.I read that we should not use password for SFTP server so i have run only with username.

Please find the below log file

 

22 GOPTIONS ACCESSIBLE;

23 FILENAME target1 SFTP USER='xx' HOST = 'xx.xx.xxx.com' DEBUG;

24 data _null_;

25 file target1;

26 do i=1 to 10;

27 put i=;

28 end;

29 run;

NOTE: Connecting to xxxx-xx.xxt.xx.com...

NOTE: The file TARGET1 is:

Filename

NOTE: ssh: connect to host xxxx.xx.xxt.com port 22: Connection timed out

NOTE: 10 records were written to the file TARGET1.

The minimum record length was 3.

The maximum record length was 4.

NOTE: DATA statement used (Total process time):

real time 1:03.21

cpu time 0.02 seconds

 

 

Super User
Posts: 9,919

Re: Create a csv file in SFTP server

You have to set up password-free authentication, or SFTP won't work from SAS.

Do a google search for

ssh key-based authentication

and you will find all necessary information.

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 21

Re: Create a csv file in SFTP server

[ Edited ]
Posted in reply to KurtBremser

Hi I have done with key pair setup and  I have to read the data iin CSV file from sub directories. Please suggest.

 

filename my data sftp "/Dir/RPTS/qtr/&CSV_file"
host="hostname" user="username";

 

ERROR: Directory or file doesnot exist

Contributor
Posts: 21

Re: Create a csv file in SFTP server

Do we have any alternate method in SAS instead of USing SFTP in SAS

filename my data sftp "/Dir/RPTS/qtr/&CSV_file"
host="hostname" user="username";

Valued Guide
Posts: 560

Re: Create a csv file in SFTP server

This is an alternate solution:

If you are trying to have your files in SFTP server, but in SAS if you have only access to Local then use WinSCP to drag and drop files from local machine to your SFTP.

Thanks,
Suryakiran
SAS Employee
Posts: 61

Re: Create a csv file in SFTP server

On Windows the value in the host= option for the sftp engine is used to lookup the profile name inside the psftp deployment. Its not the host name of the sftp server. This often trips folks up.
Ask a Question
Discussion stats
  • 7 replies
  • 596 views
  • 0 likes
  • 5 in conversation