DATA Step, Macro, Functions and more

How to Pass Agrument from SAS to batch File Using PSFTP

Reply
New Contributor
Posts: 4

How to Pass Agrument from SAS to batch File Using PSFTP

  1. I have put psftp.exe on local  server directory D:\psftp.exe
  2. I have created batch file on same local directory D:\market_extract.bat as below
  3. Batch file code as below
  4. lcd d:\landing
  5. cd  /home/Comcast/sample_data
  6. mget  market *.csv
  7. quit
  8. It is getting market files from remote directory /home/Comcast/sample data to local directory d:\landing.
  9. Using sas I have stored global variable in config file as D:\ftp_variable.sas below is the code
  10. Macro ftp_variables()
  11. %global  market_cmd_script, PSFTP_HOME, USERID, REMOTE_FTP_SERVER, PSWD;
  12. %let market_cmd_script=D:\market_extract.bat
  13. %let PSFTP_HOME_DIR=D:\psftp;
  14. %let USERID=dummy1;
  15. %let REMOTE_FTP_SERVER=ftp.dummy1.com;
  16. %let PSWD=dummy2;
  17. %mend;
  18. %ftp_variables;
  19. Now In sas i am executing this market_extract.bat using psftp commands and global variables declared in ftp_variable.sas as below in user_written_code operator
  20. %include ‘D:\ftp_variable.sas’
  21. %let var_str= &PSFTP_HOME_DIR &USERID@&REMOTE_FTP_SERVER -P 22 -pw &PSWD -batch -v –b &MARKET_FTP_CMD_SCRIPT;
  22. %let cmd_str= "&var_str";
  23. %sysexec &cmd_str;
  24. It is working fine and transferring file from remote directory to local directory.
  25. New Requirement:
  26. Now I want to remove path hard coding in batch file market_extract.bat
  27. In batch file instead of d:\landing and /home/Comcast/sample_data I want to create a global variable in
  28. Sas config file ftp_variables.sas like below
  29. Macro ftp_variables ()
  30. %global  market_cmd_script, PSFTP_HOME, USERID, REMOTE_FTP_SERVER, PSWD,LOCAL_DIR,REMOTE_DIR;
  31. %let market_cmd_script=D:\market_extract.bat
  32. %let PSFTP_HOME_DIR=D:\psftp;
  33. %let USERID=dummy1;
  34. %let REMOTE_FTP_SERVER=ftp.dummy1.com;
  35. %let PSWD=dummy2;
  36. %let LOCAL_DIR= D:\landing
  37. %let REMOTE_DIR= /home/Comcast/sample_data
  38. %mend;
  39. %ftp_variables;
  40. In batch file market_extarct.bat replacing path hard coding with Parameter as %1,%2
  41. Batch file code as below
  42. lcd %1
  43. cd  %2
  44. mget  market *.csv
  45. quit
  46. and while running this batch from sas giving argument to market_extract.bat  as below
  47. %include ‘D:\ftp_variable.sas’
  48. %let var_str= &PSFTP_HOME_DIR &USERID@&REMOTE_FTP_SERVER -P 22 -pw &PSWD -batch -v –b &MARKET_FTP_CMD_SCRIPT  &LOCAL_DIR  &REMOTE_DIR ;
  49. %let cmd_str= "&var_str";
  50. %sysexec &cmd_str;
  51. But %1 and %2 are not getting passed as path from sas so remote files are not getting transfer to local_dir.
  52. Is there any other way to pass parameter to market_extract.bat from sas  using sftp .

Regards

Rajendra Jain

PROC Star
Posts: 1,561

How to Pass Agrument from SAS to batch File Using PSFTP

I suspect the -batch option does not accept batch parameters.

&LOCAL_DIR  &REMOTE_DIR would be seen as more options after the -batch option.

Have you tried running the command from the prompt?

Maybe enclosing the whole command in quotes

-batch -v –b "&MARKET_FTP_CMD_SCRIPT  &LOCAL_DIR  &REMOTE_DIR "

would work?

Ask a Question
Discussion stats
  • 1 reply
  • 521 views
  • 0 likes
  • 2 in conversation