BookmarkSubscribeRSS Feed
DennisLam
Calcite | Level 5

Hi, I need to develop a SAS program to get a file from an remote SFTP server and rename the file after download the file. I can get the file but don't know how to send the UNIX rename command to the remote SFTP server to rename the file. Any suggestion? 

 

Following is my code that I have developed and it works well:

 

Filename SITE1 SFTP "reports/Market_Summary_date..csv"
Host="142.199.199.199" user="user1" ;

data WORK.Market_DATA ;
%let _EFIERR_ = 0; 
infile site1 delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2;
informat REPORT_DATE yymmdd10. ;

format REPORT_DATE yymmdd10. ;

input
       REPORT_DATE;

if _ERROR_ then call symputx('_EFIERR_',1);

run;

3 REPLIES 3
DartRodrigo
Lapis Lazuli | Level 10

Hi mate.

 

You can use the filename statement to rename the file using a shell script command "mv".

 

you can use the following sintax:

 

filename myfile pipe "mv myfile.txt newfile.txt";

/*or you can use the X command*/

x "mv myfile.txt newfile.txt";

Once you have permission to execute shell scripts you can use filename, call system, or x command to execute Shell scripts from SAS.

 

Check out some Shell commands or Executing Operating System Commands from Your SAS Session;

 

Hope this helps

DennisLam
Calcite | Level 5

Hi, thank you for sharing the code with me.. I have some problems on using the Filename  myfile Pipe statement.

 

If I use this 

 

Filename SITE4 PIPE 'mv reports/Market_Summary_20151102.csv reports/Market_Summary_20151102.done'
  Host="142.199.199.199" user="userid" ;
run;

 

I received an error message tha Host and user are invalid option. It seems to me that host and user cannot use with pipe. If I don't define for SFTP server IP and user id, how can I rename the file

 

If I use this 

 

Filename SITE4 PIPE 'mv reports/Market_Summary_20151102.csv reports/Market_Summary_20151102.done' ;
run;

 

I received an error message that I have insufficient authority.  

 

Please advise and thank you for your help...

DartRodrigo
Lapis Lazuli | Level 10

Hi mate,

Once you are in the enviroment of this host you don't need to use these options.

Your SAS is connected in this host, or it is another server ?

 

These are the questions that you might answer to select the option that you have to use.

Pipe is used to the server you are connected.

 

Maybe you should use instead of pipe use sftp and do the same.

 

Try this: FILENAME Statement, SFTP Access Method

 

Hope this helps

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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