hi,
I need to get a set of datasets from a remote server. And I am connected to a unix server as well. How to accomplish this ?
So task is getting a set of files or sasdatasets from a remote unix server to another unix server using SAS commands.
thanks!
sasbase9
lots of possibilities.
I prefer #1 as it is simple and robust.
Doc Muhlbaier
Duke
Hello,
Could you provide code example for using X command to launch fTP command? I cannot use command prompt and hoping to sftp files using user pwd using the X command.
Thanks,
Neha
Could you provide an example x command to copy a text file using SAS Studio?
From where to where? You need to explain your requirements more fully. Also it's not a good idea to add to 10 year old posts. You should create a new one.
@sujaybshha wrote:
Could you provide an example x command to copy a text file using SAS Studio?
In most environments i have access to, the xcmd is disabled in SAS Studio session. So you may want to check the status of xmcd:
proc options option=xcmd;
run;
Some sample code you can use for ftp (All macro variables have to be set to your reality):
filename ftpcom "&ftpcommands";
* Commands for ftp session;
data _null_;
file ftpcom pad;
* ftp session user and password;
put "user &user &pwd";
* Disable prompting cmd;
put 'prom no';
* Enable Binary transfer mode cmd;
put 'bin';
* Go to local folder cmd;
put "lcd &excel";
* Go to remote folder cmd;
put "cd &sharefolder";
* Get needed files cmd;
put 'mget *.tgz';
stop;
run;
filename doftp pipe "ftp -n &host < &ftpcommands";
* Enable ftp session and pass it the commands file;
data _null_;
infile doftp;
input;
put _infile_;
run;
As said before, you can also use a Connect Session or create a NFS to the drive.
One doubt--
What does "&ftpcommands" in first filename statement correspond to ?
thanks again for help!
sasbasls wrote:
One doubt--
What does "&ftpcommands" in first filename statement correspond to ?
thanks again for help!
It's the name of the file you pass to the ftp session with the commands that will be executed.
On a windows environment it would be something like: "c:\ftp_commands.txt".
On a unix environment it would be something like: "/home/sas/ftp_commands.txt".
In order to transfer files in an ftp session in batch you have to build your ftp commands file to pass to the ftp session, with the same commands you would use when typing directly in an ftp session.
Take this example and the sample i gave you with some modifications on macro variable names between two unix hosts:
You want to transfer dataset "wanted.sas7bdat", placed in "/sasdata/source" on a remote server with ip "10.203.22.35", to "/sasdata/target" in the local server (where your sas session is invoked). The remote server ftp user is "sasftp" and the password is "12345". Your "ftpcommands" file will be built and stored in "/home/trash" folder in the local host.
sample:
filename ftpcom "&ftpcommands";
* Commands for ftp session;
data _null_;
file ftpcom pad;
* ftp session user and password;
put "user &user &pwd";
* Disable prompting cmd;
put 'prom no';
* Enable Binary transfer mode cmd;
put 'bin';
* Go to local folder cmd;
put "lcd &target";
* Go to remote folder cmd;
put "cd &source";
* Get needed files cmd;
put 'mget &wanted_files';
stop;
run;
filename doftp pipe "ftp -n &host < &ftpcommands";
* Enable ftp session and pass it the commands file;
data _null_;
infile doftp;
input;
put _infile_;
run;
The macro variables for the sample code to work should look like this:
%let ftpcommands=/home/trash/ftp_commands;
%let user=sasftp;
%let pass=12345;
%let host=10.203.22.35;
%let source=/sasdata/source;
%let target=/sasdata/target;
%let wanted_files=A.sas7bdat
Since we're using mget ftp command to get the files we are allowed to use wildcards so, if the dataset was indexed you could use one wild card to bring both table and index with the same command.
%let wanted_files=wanted.sas7*;
Hope this helps.
PA.
u can transfer by using some macro u need to craeate batch file for each file and need to give all credential for unix sever then u can transfer give me ur mail id i will send sample code for htis.
What is the order of the code in which it must be created or executed?
You started with filename ftpcom "&ftpcommands".
Where is the above command be give?
SAS has already supported sftp access.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.