Moving files from UNIX to Windows network location using SAS EG 9.4

Reply
Occasional Contributor
Posts: 11

Moving files from UNIX to Windows network location using SAS EG 9.4

[ Edited ]

I have a few files in unix. I am trying to move these to windows network location using SAS.

 

Current location: /dk/dk_new/current_month

Windows location: \\dk_current\current_mth

File name:

Test1.dat

Test1.cntl

Test2.dat

Test2.cntl

I tried systask and X command but unable to copy these files to windows location. Please advice.

 

Super User
Posts: 1,231

Re: Moving files from UNIX to Windows network location using SAS EG 9.4

1) On unix run PROC CPORT to create a portable file.

2) Copy the file or do ftp binary to the windows.

3) On windows run PROC CIMPORT to convert the poratable file into sas datasets.

 

An exampe:

 

1) libname my_lib "/dk/dk_new/current_month";

    filename cpt '/dk/dk_new/lib_file.cpt';

    proc cport lib=my_lib file=cpt; select _ALL_; run;  /* all sas datasets */

                                                          /* for one dataset use: proc cport data=mylib.test1 file=cpt; run; */

 

2) copy files or do ftp binary from unix to windows.

 

3) In windows environment:

    libname my_lib '...path to folder ...";

    filename cpt '... path to above file ...';  

    proc cimport lib=my_lib file=cpt; run;

 

 

 

 

 

Respected Advisor
Posts: 3,831

Re: Moving files from UNIX to Windows network location using SAS EG 9.4

Esteemed Advisor
Posts: 6,646

Re: Moving files from UNIX to Windows network location using SAS EG 9.4

[ Edited ]

It depends on the available connections.

If the Windows share is mounted on the UNIX system, or the UNIX directory is available as a network resource in Windows, you can simply copy the files.

If not, you will need another type of connection (SSH) so you can use sftp.

 

On which side (Windows or UNIX) is the SAS process running? Are you using SAS with Display Manager, Enterprise Guide or SAS Studio?

Belay that; you use EG with SAS 9.4. Is SAS (not the EG!) running on UNIX or on Windows?

 

(From your post I guessed that you want to copy non-SAS files)

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 11

Re: Moving files from UNIX to Windows network location using SAS EG 9.4

SAS is running on UNIX. Yes, you are right I am copying the non SAS files.

Esteemed Advisor
Posts: 6,646

Re: Moving files from UNIX to Windows network location using SAS EG 9.4

So the next question is, how are those two locations

Current location: /dk/dk_new/current_month

Windows location: \\dk_current\current_mth

connected?

Does either server have a mount of the other, do they have a mounted network resource in common, or will we need to use a network copying tool?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 11

Re: Moving files from UNIX to Windows network location using SAS EG 9.4

I am using network copying tool to move the data from windows to UNIX and vise-versa

Esteemed Advisor
Posts: 6,646

Re: Moving files from UNIX to Windows network location using SAS EG 9.4

Since SAS runs on the UNIX side, we will have to use the sftp command from UNIX:

%let filename=Test1.dat;
%let username=%sysget(USER);

filename oscmd pipe "sftp /dk/dk_new/current_month/&filename..dat &username.@dk_current:/current_mth/&filename..dat 2>&1";

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

filename oscmd clear;

Note that this assumes

- your userid is the same across both platforms

- you have set up password-free SSH access by using a public/private key pair

 

The data step will retrieve all system messages and put them into the SAS log.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 11

Re: Moving files from UNIX to Windows network location using SAS EG 9.4

I am still not able to copy the files. I am getting below message in log.

ssh: /dk/dk_new/current_month/test1.dat: Name or service not known

Couldn't read packet: Connection reset by peer

 

Esteemed Advisor
Posts: 6,646

Re: Moving files from UNIX to Windows network location using SAS EG 9.4

I gave you a wrong example for the sftp command, my bad. Have to look at the manual myself everytime I use it.

filename oscmd pipe "sftp &username.@dk_current:/current_mth <<< $'put /dk/dk_new/current_month/&filename..dat' 2>&1";

This basically starts sftp into interactive mode and feeds it the command to upload the file.

As an alternative, you could use my original example and replace sftp with scp, as scp should support my intended upload syntax.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 9 replies
  • 190 views
  • 1 like
  • 4 in conversation