Hi ,
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
in abc.bat
lcd %1
cd /home/comnest/
mget mkt*.csv
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
lcd d:\raj
cd /home/comnest
mget mkt*.csv
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 .
have you tried passing the -b parameter as a quoted string containing the .bat file and it's parameter?
Hi Peter
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
lcd d:\landing\
cd /home/comnest/
mget mkt*.csv
quit
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
%1.
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.
extract_market_files.bat
lcd %1
cd /home/comnest/
mget mkt*.csv
quit
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.
I did a test using SAS9.2 on Wndows 7:
Contents of test.bat file:
echo Parameter was %1;
SAS Code:
%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;
Conclusion:
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.
Thanks
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.
Discussion moved to the SAS Macro Facility, Data Step and SAS Language Elements so that more people might find it.
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;
data _null_;
infile 'abc.bat' ;
file script;
input;
_infile_ = tranwrd(_infile_,'%1',"&sdir");
put _infile_;
run;
%sysexec psftp.exe username@hostname -p portnumber(22) -pw password -batch -b %sysfunc(pathname(script)) ;
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 25. 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.