BookmarkSubscribeRSS Feed
sasbasls
Calcite | Level 5

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

11 REPLIES 11
Doc_Duke
Rhodochrosite | Level 12

lots of possibilities. 

  1. You could use the SAS 'X" command to launch an ftp script to do the copies. 
  2. If the datasets are all SAS datasets and you have SAS Connect running, you could use PROC COPY to move the datasets from one library to another. 
  3. Depending on the flavor(s) of Unix and local permissions, you might be able to NFS mount the directories on the remote Unix box and treat them as local.

I prefer #1 as it is simple and robust.

Doc Muhlbaier

Duke

NehaMutta
Calcite | Level 5

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

sujaybshha
Fluorite | Level 6

Could you provide an example x command to copy a text file using SAS Studio?

SASKiwi
PROC Star

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.

andreas_lds
Jade | Level 19

@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;
PAzevedo
Fluorite | Level 6

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.

sasbasls
Calcite | Level 5

One doubt--

What does "&ftpcommands" in first filename statement correspond to ?

thanks again for help!

PAzevedo
Fluorite | Level 6

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.

bachusudheer
Calcite | Level 5

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.

SASPhile
Quartz | Level 8

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-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 11 replies
  • 16710 views
  • 0 likes
  • 10 in conversation