08-22-2011 02:25 AM
I am using PSFTP for executing dos batch file in sas.
i want to pass parameter to batch file in sas and in batch file i have interpreted that passed parameter as %1 like below
%sysexec psftp.exe username@hostname -p portnumber(22) -pw password -batch -b abc.bat d:\raj
but that %1 is not working as i am not getting any file transfer from /home/comnest to local directory d:\raj.
if i remove d:raj as below
%sysexec psftp.exe username@hostname -p portnumber(22) -pw password -batch -b abc.bat
and in abc.bat
is working and getting files from /home/comnest to local directory d:\raj
..but i want to pass parameter to abc.bat d:\raj
and can it replace %1 in abc.bat with value d:\raj
i have tried many times but it did not work
can you please help me on this .
08-23-2011 12:40 AM
i have created batch file extract_market_files.bat which is ftping file from remote ftp server localtion /home/comnest/ to local machine directory d:\landing\
extract_market_files.bat is as below
i am trying below command in sas for executing dos batch file which is running correctly.
%sysexec "D:\psftp username@hostname -P 22 -pw password -batch -v -b D:\extract_market_files.bat"
remote file are getting ftped to local directory d:\landing\.
but i wanted to pass local directory 'd:\landing\' as a parameter while executing extract_market_files.bat in sas and read that parameter in dos batch file using
something like below
%sysexec "D:\psftp username@hostname -P 22 -pw password -batch -v -b D:\extract_market_files.bat d:\landing\"
in batch file %1 should understand value d:\landing.
it is not ftping file from remote ftp location /home/comnest/ to local directory d:\landing\.
can you please suggest how to pass parameter from sas to dos batch file using psftp.
08-23-2011 09:47 PM
I did a test using SAS9.2 on Wndows 7:
Contents of test.bat file:
echo Parameter was %1;
%sysexec "c:\temp\test.bat Testing > c:\temp\result.txt ";
result.txt file contents after run:
C:\Users\SASJedi>echo Parameter was Testing;
Parameter was Testing;
Parameter is passing OK to a normal DOS batch file
Upon reviewing the documentation for PSFTP, I found instructions for writing scripts, but none for accepting parameters. Perhaps this is problems stems from the PSFTP program itself. Consider re-writing your job as a DOS batch file (which will accept parameters) and let the DOS batch file execute PSFTP, or use a DATA _NULL_ step to write a customized copy of the extract_market_files.bat file which contains the hard-coded local directory name so it doesn't have to be passed as a parameter.
08-24-2011 07:44 AM
my requirement is to pass parameter to dos batch file from sas using psftp protocol as file are residing on sftp server.
any information for passing parameter to dos batch file from sas using psftp will be helpful.
08-22-2011 10:44 AM
Discussion moved to the SAS Macro Facility, Data Step and SAS Language Elements so that more people might find it.
08-24-2011 09:13 AM
It does not look like the psftp program does what you want it to do. You can test that by taking SAS out of the problem and issuing the proposed command from a DOS prompt.
I think it would be much easier to use SAS to write the script for psftp than to depend on an external file. But you could use an external file as a model for the script that SAS would write. The datastep below will replace all references to '%1' with the actual directory.
%let sdir=d:\raj ;
filename script temp;
infile 'abc.bat' ;
_infile_ = tranwrd(_infile_,'%1',"&sdir");
%sysexec psftp.exe username@hostname -p portnumber(22) -pw password -batch -b %sysfunc(pathname(script)) ;