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

Hi All,

 

I have a SAS Dataset in one of my SAS Environment which I move it to another environment using SFTP in SAS Code.

I could do this by logging in to Linux box and then move it manually, but for a project I have to move this multiple times. Could you please assist me with sample code using which I could do the same?

 

Both environments are on LINUX Hosts.

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

My preferred method of using the commandline is this:

filename oscmd pipe "sftp sourcefile targetfile 2>&1";

data _null_;
infile oscmd;
input;
put _infile_;
run;

filename oscmd clear;

The 2>&1 redirects stderr (standard error output) to stdout, so you get any error messages into your infile. The data _null_ then executes the command and writes output to the SAS log.

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User

Set up public/private key authentication between the users on both hosts. Then you can use sftp from the commandline without the need to log on.

To use this from SAS code, you will need to have xcmd enabled, of course.

AnandVyas
Ammonite | Level 13

It's working fine with commandline, Could you please direct me to a sample code that I can use to do it from sas code(EG)?

 

thanks

Kurt_Bremser
Super User

My preferred method of using the commandline is this:

filename oscmd pipe "sftp sourcefile targetfile 2>&1";

data _null_;
infile oscmd;
input;
put _infile_;
run;

filename oscmd clear;

The 2>&1 redirects stderr (standard error output) to stdout, so you get any error messages into your infile. The data _null_ then executes the command and writes output to the SAS log.

AnandVyas
Ammonite | Level 13
Thanks, this resolved the issue.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 4 replies
  • 1696 views
  • 0 likes
  • 2 in conversation