Guys , I need to copy file from windows shared network to the unix path , sas running on unix environment,
.
can any one help me with the right syntax we can use for it??
Is your windows server mapped/mounted to the Unix server? Or are you running software like Samba to make the Windows server visible to Unix? If not, Unix will not be able to "see" the windows server.
If you want to run the copy action from a SAS session running on a UNIX server, you need to save the file in Windows to a location that your SAS server can "see", or you need to use a file copy utility (or filename ftp/sftp), and have a FTP/SFTP server program running on the Windows side.
Depending on what you have (and if you can run external commands from your SAS session), we can determine which method to use.
Thanks @Kurt_Bremser .
can you please share the document or link where I can find the FTP sytanx for SAS
Look in the SAS documentation, section Global Statements:
FILENAME SFTP is just two items down in the navigation pane.
Once you have defined a file reference to the FTP source, you can use it as infile in a data step or as datafile in a proc import.
I have refered one of your previous answer for my problem .
Code is running fine but it is not actually performing the expected operation,. can you please help where i went wrong
%let filename=Arun.csv;
%let username=%sysget(USER);
filename oscmd pipe "sftp &username. windowspath/&filename @unixpath/&filename..dat 2>&1";
data _null_;
infile oscmd;
input;
put _infile_;
run;
filename oscmd clear;
I don't see the SFTP hostname in your code. You might need &username@&hostname .
NOTE: Compression was disabled for data set WORK.NULL because compression
overhead would increase the size of the data set.
NOTE: The infile OSCMD is:
Pipe command="sftp
N****@\\*****/Arun.csv <<< $'put
**********/Arun.csv' 2>&1"
/bin/ksh: syntax error at line 1 : `<' unexpected
NOTE: 1 record was read from the infile OSCMD.
The minimum record length was 49.
The maximum record length was 49.
NOTE: The data set WORK.NULL has 1 observations and 1 variables.
@arunrami wrote:
NOTE: Compression was disabled for data set WORK.NULL because compression
overhead would increase the size of the data set.
NOTE: The infile OSCMD is:
Pipe command="sftp
N****@\\*****/Arun.csv <<< $'put
**********/Arun.csv' 2>&1"/bin/ksh: syntax error at line 1 : `<' unexpected
NOTE: 1 record was read from the infile OSCMD.
The minimum record length was 49.
The maximum record length was 49.
NOTE: The data set WORK.NULL has 1 observations and 1 variables.
This cannot be the log of may code, as I do not use any INPUT redirection (<), I only redirect stderr to stdout.
Please find this , exactly used your syntax.
intention : need to copy csv file from windows to unix
NOTE: Compression was disabled for data set WORK.NULL because compression
overhead would increase the size of the data set.
NOTE: The infile OSCMD is:
Pipe command="sftp N****
\\****/Arun.csv
@/******/Arun.csv 2>&1"
usage: sftp [-1246aCfpqrv] [-B buffer_size] [-b batchfile] [-c cipher]
[-D sftp_server_path] [-F ssh_config] [-i identity_file] [-l limit]
[-o ssh_option] [-P port] [-R num_requests] [-S program]
[-s subsystem | sftp_server] host
sftp [user@]host[:file ...]
sftp [user@]host[:dir[/]]
sftp -b batchfile [user@]host
NOTE: 7 records were read from the infile OSCMD.
The minimum record length was 32.
The maximum record length was 77.
Make sure you can get the command to run from the command prompt without using SAS at all.
The SFTP command is telling you that the syntax of your command is wrong. It wants these three pieces of information.
sftp [user@]host[:file ...]
So I would assume that would look like:
sftp myuser@myhost:\\servername\sharename\dirname\filename.ext
Note there is no place to put a password so you either need to have previously shared keys with the host, or use the -i option to specify the file with the user credentials that will let you connect to the host.
Please post the link of my post where you got the sftp code from. (It's hard for me to find that particular post, as I have dealt with sftp transfers quite often here on the ciommunities)
It may be that the post needs correction.
That example was for copying a file from the SAS server to a remote destination. It is not intended for retrieving a dataset.
The filename statement for retrieving a file needs to be
filename oscmd pipe "sftp &user.@&host.:&external_path./extfilename. &local_path./&locfilename. 2>&1";
Note that passwordless authentication needs to be set up beforehand. SSH does not support passwords on the commandline, for security reasons.
To make development of the external command easier, I suggest you log ion to your SAS server with SSH yourself and test the command on the commandline till it works there. Note that I work on AIX, and sftp syntax on Linux might be slightly different.
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 16. 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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: