BookmarkSubscribeRSS Feed
Ishaan
Calcite | Level 5

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.

 

13 REPLIES 13
Shmuel
Garnet | Level 18

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;

 

 

 

 

 

Kurt_Bremser
Super User

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)

Ishaan
Calcite | Level 5

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

Kurt_Bremser
Super User

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?

Ishaan
Calcite | Level 5

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

Kurt_Bremser
Super User

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.

Ishaan
Calcite | Level 5

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

 

Kurt_Bremser
Super User

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.

jrsousa2
Obsidian | Level 7

It's incredible how some of the answers are lax and lazy. I know you're contributing your answers for free, but still.

@dk_current:/current_mth/&filename..dat 2>&1

What is @dk_current? And what is the &1?

 

Is this supposed to be some macro variable, is it a path in the windows system? Those slashes are not windows, so this can't be moving from Unix to windows. This is so wrong!

Maybe if you can provide us with the documentation you say you refer to, I'd appreciate it, and sorry for my rant.

 

 

jrsousa2
Obsidian | Level 7

Hi Kurt, SAS support has said filename SFTP doesn't work from Unix to Windows, so, is this

solution you proposed different, is it a work-around?

 

Per SAS support, SFTP might only work from Unix to windows if an OpenSSH is installed in Windows, but they don't support it.

 

Can you please explain what your solution is really doing then, because the first few examples that you posted don't make any sense.

jrsousa2
Obsidian | Level 7

At a second glance, your answers add nothing, you're supposed to explain yourself here, not send people to other pages that they can find with Google if they want to.

 

Nevermind, if you don't want to or most likely can't provide a valuable answer, then don't.

What you posted is wrong, it's not a solution to move a file from Unix to Windows using SFTP,

so your answer is just misleading Googlers like me who end up here. 

Even if your code is right, it's not easy to adapt it for the case of the users who come to this page for help because you provided the least possible amount of explanation for us to make sense it.

 

No wonder your answers got 0 likes.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 13 replies
  • 6641 views
  • 1 like
  • 5 in conversation